mirror of
https://github.com/pezkuwichain/kurdistan_blockchain-akademy.git
synced 2026-04-22 02:07:57 +00:00
clarifications from upstream
This commit is contained in:
@@ -114,7 +114,8 @@ pub trait ProvideEnergy<F: Fuel> {
|
||||
/// Convert the amount of fuel in `f` with an exact efficiency of `e`.
|
||||
///
|
||||
/// NOTE: all efficiencies are interpreted as u8 values that can be at most 100, and represent a
|
||||
/// percent.
|
||||
/// percent. If an efficiency above 100 is supplied, the code should treat it as 100. That is to
|
||||
/// say that the efficiency is "saturating" at 100%.
|
||||
///
|
||||
/// This method must be provided as it will be the same in all implementations.
|
||||
fn provide_energy_with_efficiency(&self, f: FuelContainer<F>, e: u8) -> <F as Fuel>::Output {
|
||||
@@ -158,7 +159,8 @@ impl<const DECAY: u32, F: Fuel> ProvideEnergy<F> for InternalCombustion<DECAY> {
|
||||
|
||||
/// A hypothetical device that can, unlike the `InternalCombustion`, consume **any fuel** that's of
|
||||
/// type `trait Fuel`. It can provide a fixed efficiency regardless of fuel type. As before,
|
||||
/// EFFICIENCY is a u8 whose value should not exceed 100 and is interpreted as a percent.
|
||||
/// EFFICIENCY is a u8 whose value should not exceed 100, is interpreted as a percent, and should
|
||||
/// saturate at 100% when a higher value is supplied.
|
||||
pub struct OmniGenerator<const EFFICIENCY: u8>;
|
||||
|
||||
// NOTE: implement `ProvideEnergy` for `OmniGenerator` using only one `impl` block.
|
||||
|
||||
@@ -62,13 +62,16 @@ impl OutcomeCount for Vec<Outcome> {
|
||||
// But all of that is a lot of boilerplate. Wouldn't it be nice to have a `derive` macro that
|
||||
// exactly does this, on any enum?
|
||||
//
|
||||
// So, for any `enum Foo { X, Y, .. }`, `#[derive(CountOf)]` would generate a trait `CountOfFoo`,
|
||||
// with functions named `fn x_count`, `fn y_count` etc. Finally, it would implement `CountOfFoo` for
|
||||
// `Vec<Foo>`.
|
||||
// In that case, for any `enum Foo { X, Y, .. }`, `#[derive(CountOf)]` would generate a trait
|
||||
// `CountOfFoo`, with functions named `fn x_count`, `fn y_count` etc. Finally, it would implement
|
||||
// `CountOfFoo` for `Vec<Foo>`.
|
||||
//
|
||||
// And heck, you could then easily implement it for other collections of `Foo`, such as
|
||||
// `HashMap<_, Foo>` etc.
|
||||
|
||||
// This problem does NOT require you to implement such a macro. Perhaps you will encounter that
|
||||
// macro problem somewhere in the future.
|
||||
|
||||
/// This function is not graded. It is just for collecting feedback.
|
||||
/// On a scale from 0 - 255, with zero being extremely easy and 255 being extremely hard,
|
||||
/// how hard did you find this section of the exam.
|
||||
|
||||
+8
-4
@@ -9,7 +9,7 @@
|
||||
// Your task here is to create an analogous macro for creating hashmaps pre-populated with literal
|
||||
// values. The macro should be called like follows:
|
||||
//
|
||||
// let map1: HashMap<u32, u32> = map![1 =>2, 3 => 4, 5 => 6)];
|
||||
// let map1: HashMap<u32, u32> = map![1 =>2, 3 => 4, 5 => 6];
|
||||
#[macro_export]
|
||||
macro_rules! map {
|
||||
( $($todo:tt)* ) => {
|
||||
@@ -25,7 +25,7 @@ macro_rules! map {
|
||||
/// generate this implementation for us, as such:
|
||||
///
|
||||
/// ```
|
||||
/// use pba_qualifier_exam::impl_get;
|
||||
/// use pba_entrance_exam::impl_get;
|
||||
/// impl_get! {
|
||||
/// // implements `Get<u32>` for `struct Six`
|
||||
/// Six: u32 = 6;
|
||||
@@ -101,7 +101,11 @@ mod tests {
|
||||
// you should be able to make these work.
|
||||
// assert_eq!(Foo::get(), 10);
|
||||
// assert_eq!(Bar::get(), 42);
|
||||
// const CONST: u32 = Baz::get();
|
||||
// assert_eq!(CONST, 42);
|
||||
// assert_eq!(Baz::get(), 21);
|
||||
|
||||
// As an extra, ungraded, challenge, try to make this work.
|
||||
// This is not part of the main problem because it requires the nightly compiler.
|
||||
// const CONST: u16 = Baz::get();
|
||||
// assert_eq!(CONST, 21);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user