From 6ec6ec04da1763171379d6bcabf90083957fd3dc Mon Sep 17 00:00:00 2001 From: Joshy Orndorff Date: Fri, 21 Apr 2023 11:29:04 -0400 Subject: [PATCH] clarifications from upstream --- src/h_advanced_traits.rs | 6 ++++-- src/i_extension_traits.rs | 9 ++++++--- src/k_macros.rs | 12 ++++++++---- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/h_advanced_traits.rs b/src/h_advanced_traits.rs index cf534d9..7e27f7e 100644 --- a/src/h_advanced_traits.rs +++ b/src/h_advanced_traits.rs @@ -114,7 +114,8 @@ pub trait ProvideEnergy { /// 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, e: u8) -> ::Output { @@ -158,7 +159,8 @@ impl ProvideEnergy for InternalCombustion { /// 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; // NOTE: implement `ProvideEnergy` for `OmniGenerator` using only one `impl` block. diff --git a/src/i_extension_traits.rs b/src/i_extension_traits.rs index a76f5ca..fb97278 100644 --- a/src/i_extension_traits.rs +++ b/src/i_extension_traits.rs @@ -62,13 +62,16 @@ impl OutcomeCount for Vec { // 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`. +// 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`. // // 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. diff --git a/src/k_macros.rs b/src/k_macros.rs index a22f46e..d2f9153 100644 --- a/src/k_macros.rs +++ b/src/k_macros.rs @@ -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 = map![1 =>2, 3 => 4, 5 => 6)]; +// let map1: HashMap = 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` 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); } }