diff --git a/Cargo.toml b/Cargo.toml index 0efc6b3..3d22c77 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mode" -version = "0.1.0" +version = "0.1.1" authors = ["Andrew Thomas Christensen "] edition = "2018" diff --git a/README.md b/README.md index f03933f..2ad9287 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ impl Mode for Working { fn as_base_mut(&mut self) -> &mut Self::Base { self } // This function allows the current Mode to swap to another Mode, when ready. - fn get_transition(&mut self) -> Option>> { + fn get_transition(&mut self) -> Option>> { if self.hours_worked == 4 || self.hours_worked >= 8 { // To swap to another Mode, a Transition function is returned, which will consume // the current Mode and return a new Mode to be swapped in as active. @@ -61,7 +61,7 @@ impl Mode for Eating { type Base = Activity; fn as_base(&self) -> &Self::Base { self } fn as_base_mut(&mut self) -> &mut Self::Base { self } - fn get_transition(&mut self) -> Option>> { + fn get_transition(&mut self) -> Option>> { if self.calories_consumed >= 500 { if self.hours_worked >= 8 { // Time for bed! @@ -90,7 +90,7 @@ impl Mode for Sleeping { type Base = Activity; fn as_base(&self) -> &Self::Base { self } fn as_base_mut(&mut self) -> &mut Self::Base { self } - fn get_transition(&mut self) -> Option>> { + fn get_transition(&mut self) -> Option>> { if self.hours_rested >= 8 { // Time for breakfast! Some(Box::new(|_| { Eating { hours_worked: 0, calories_consumed: 0 } })) diff --git a/examples/counter.rs b/examples/counter.rs index 1b274d5..a59598e 100644 --- a/examples/counter.rs +++ b/examples/counter.rs @@ -35,7 +35,7 @@ impl Mode for UpMode { type Base = CounterMode; fn as_base(&self) -> &Self::Base { self } fn as_base_mut(&mut self) -> &mut Self::Base { self } - fn get_transition(&mut self) -> Option>> { + fn get_transition(&mut self) -> Option>> { if self.counter == self.target { // If we've reached the target value, start counting down to (roughly) the median value. Some(Box::new( @@ -68,7 +68,7 @@ impl Mode for DownMode { type Base = CounterMode; fn as_base(&self) -> &Self::Base { self } fn as_base_mut(&mut self) -> &mut Self::Base { self } - fn get_transition(&mut self) -> Option>> { + fn get_transition(&mut self) -> Option>> { const GOAL : i32 = 10; if self.counter == GOAL { // When we finally count down to the goal value, end the program by swapping in a "finished" state. @@ -107,7 +107,7 @@ impl Mode for FinishedMode { type Base = CounterMode; fn as_base(&self) -> &Self::Base { self } fn as_base_mut(&mut self) -> &mut Self::Base { self } - fn get_transition(&mut self) -> Option>> { + fn get_transition(&mut self) -> Option>> { // We're finished calculating, so we never want to transition. None } diff --git a/src/automaton.rs b/src/automaton.rs index 2cd6136..49f4121 100644 --- a/src/automaton.rs +++ b/src/automaton.rs @@ -48,7 +48,7 @@ use std::fmt; /// # type Base = MyMode; /// # fn as_base(&self) -> &Self::Base { self } /// # fn as_base_mut(&mut self) -> &mut Self::Base { self } -/// # fn get_transition(&mut self) -> Option>> { None } +/// # fn get_transition(&mut self) -> Option>> { None } /// # } /// # /// // Use with_initial_mode() to create the Automaton with an initial state. @@ -65,7 +65,7 @@ use std::fmt; pub struct Automaton where Base : ?Sized { - current_mode : Box>, + current_mode : Box>, } impl Automaton @@ -130,7 +130,7 @@ impl Automaton /// type Base = Self; /// fn as_base(&self) -> &Self { self } /// fn as_base_mut(&mut self) -> &mut Self { self } - /// fn get_transition(&mut self) -> Option>> { + /// fn get_transition(&mut self) -> Option>> { /// // TODO: Logic for transitioning between states goes here. /// Some(Box::new( /// |previous : Self| { @@ -195,7 +195,7 @@ impl Default for Automaton /// type Base = MyBase; /// fn as_base(&self) -> &Self::Base { self } /// fn as_base_mut(&mut self) -> &mut Self::Base { self } -/// fn get_transition(&mut self) -> Option>> { None } // TODO +/// fn get_transition(&mut self) -> Option>> { None } // TODO /// } /// /// let automaton = Automaton::with_initial_mode(MyMode { foo: 3, bar: "Hello, World!" }); diff --git a/src/lib.rs b/src/lib.rs index 6ff7551..297c27a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,7 +39,7 @@ //! fn as_base_mut(&mut self) -> &mut Self::Base { self } //! //! // This function allows the current Mode to swap to another Mode, when ready. -//! fn get_transition(&mut self) -> Option>> { +//! fn get_transition(&mut self) -> Option>> { //! if self.hours_worked == 4 || self.hours_worked >= 8 { //! // To swap to another Mode, a Transition function is returned, which will consume //! // the current Mode and return a new Mode to be swapped in as active. @@ -64,7 +64,7 @@ //! type Base = Activity; //! fn as_base(&self) -> &Self::Base { self } //! fn as_base_mut(&mut self) -> &mut Self::Base { self } -//! fn get_transition(&mut self) -> Option>> { +//! fn get_transition(&mut self) -> Option>> { //! if self.calories_consumed >= 500 { //! if self.hours_worked >= 8 { //! // Time for bed! @@ -93,7 +93,7 @@ //! type Base = Activity; //! fn as_base(&self) -> &Self::Base { self } //! fn as_base_mut(&mut self) -> &mut Self::Base { self } -//! fn get_transition(&mut self) -> Option>> { +//! fn get_transition(&mut self) -> Option>> { //! if self.hours_rested >= 8 { //! // Time for breakfast! //! Some(Box::new(|_| { Eating { hours_worked: 0, calories_consumed: 0 } })) diff --git a/src/mode.rs b/src/mode.rs index 78efc18..b32662b 100644 --- a/src/mode.rs +++ b/src/mode.rs @@ -38,7 +38,7 @@ use crate::Transition; /// type Base = MyMode; /// fn as_base(&self) -> &Self::Base { self } /// fn as_base_mut(&mut self) -> &mut Self::Base { self } -/// fn get_transition(&mut self) -> Option>> { +/// fn get_transition(&mut self) -> Option>> { /// // Transition to ModeB. ModeA can swap to ModeB because both share the same Base. /// Some(Box::new(|previous : Self| { ModeB })) /// } @@ -51,7 +51,7 @@ use crate::Transition; /// type Base = MyMode; /// fn as_base(&self) -> &Self::Base { self } /// fn as_base_mut(&mut self) -> &mut Self::Base { self } -/// fn get_transition(&mut self) -> Option>> { None } // None means don't transition. +/// fn get_transition(&mut self) -> Option>> { None } // None means don't transition. /// } /// ``` /// @@ -80,8 +80,8 @@ use crate::Transition; pub trait Mode : 'static { /// Represents the user-facing interface for the `Mode` that will be exposed via the `Automaton`. In order to be /// used with an `Automaton`, the `Base` type of the `Mode` **must** match the `Base` type of the `Automaton`. This - /// is so that the `Automaton` can provide `get_mode()` and `get_mode_mut()` functions that return a reference to - /// the `Mode` as the `Base` type. + /// is so that the `Automaton` can provide `borrow_mode()` and `borrow_mode_mut()` functions that return a reference + /// to the `Mode` as the `Base` type. /// type Base : ?Sized; @@ -100,5 +100,5 @@ pub trait Mode : 'static { /// /// See [`Transition`](trait.Transition.html) for more details. /// - fn get_transition(&mut self) -> Option>>; + fn get_transition(&mut self) -> Option>>; } \ No newline at end of file diff --git a/src/mode_wrapper.rs b/src/mode_wrapper.rs index c16df3b..0c5f600 100644 --- a/src/mode_wrapper.rs +++ b/src/mode_wrapper.rs @@ -26,7 +26,7 @@ pub trait AnyModeWrapper { /// this yields a `Transition`, the `Transition` will be called on the inner `Mode` and a new `ModeWrapper` around /// the `Mode` to be swapped in will be returned. /// - fn perform_transitions(&mut self) -> Option>>; + fn perform_transitions(&mut self) -> Option>>; } /// Wraps a specific instance of `Mode`, allowing the parent `Automaton` to handle `Transition`s between that instance @@ -66,7 +66,7 @@ impl AnyModeWrapper for ModeWrapper self.mode.as_mut().unwrap().as_base_mut() } - fn perform_transitions(&mut self) -> Option>> { + fn perform_transitions(&mut self) -> Option>> { // Retrieve the desired transition, if any, from the inner Mode. match self.mode.as_mut().unwrap().get_transition() { None => None, diff --git a/src/transition.rs b/src/transition.rs index d132c87..0354a82 100644 --- a/src/transition.rs +++ b/src/transition.rs @@ -40,7 +40,7 @@ use crate::{AnyModeWrapper, Mode, ModeWrapper}; /// # fn as_base(&self) -> &Self::Base { self } /// # fn as_base_mut(&mut self) -> &mut Self::Base { self } /// // ... -/// fn get_transition(&mut self) -> Option>> { +/// fn get_transition(&mut self) -> Option>> { /// # let some_condition = true; /// # let some_other_condition = true; /// // ... @@ -65,7 +65,7 @@ use crate::{AnyModeWrapper, Mode, ModeWrapper}; /// # type Base = MyMode; /// # fn as_base(&self) -> &Self::Base { self } /// # fn as_base_mut(&mut self) -> &mut Self::Base { self } -/// # fn get_transition(&mut self) -> Option>> { None } +/// # fn get_transition(&mut self) -> Option>> { None } /// # } /// # /// # struct YetAnotherMode; @@ -75,7 +75,7 @@ use crate::{AnyModeWrapper, Mode, ModeWrapper}; /// # type Base = MyMode; /// # fn as_base(&self) -> &Self::Base { self } /// # fn as_base_mut(&mut self) -> &mut Self::Base { self } -/// # fn get_transition(&mut self) -> Option>> { None } +/// # fn get_transition(&mut self) -> Option>> { None } /// # } /// ``` /// @@ -103,7 +103,7 @@ use crate::{AnyModeWrapper, Mode, ModeWrapper}; /// # } /// # /// struct SomeMode { -/// queued_transition : Option>> +/// queued_transition : Option>> /// } /// /// impl MyMode for SomeMode { @@ -124,7 +124,7 @@ use crate::{AnyModeWrapper, Mode, ModeWrapper}; /// # fn as_base(&self) -> &Self::Base { self } /// # fn as_base_mut(&mut self) -> &mut Self::Base { self } /// // ... -/// fn get_transition(&mut self) -> Option>> { +/// fn get_transition(&mut self) -> Option>> { /// # let ready_to_transition = true; /// // ... /// if ready_to_transition && self.queued_transition.is_some() { @@ -142,7 +142,7 @@ use crate::{AnyModeWrapper, Mode, ModeWrapper}; /// # type Base = MyMode; /// # fn as_base(&self) -> &Self::Base { self } /// # fn as_base_mut(&mut self) -> &mut Self::Base { self } -/// # fn get_transition(&mut self) -> Option>> { None } +/// # fn get_transition(&mut self) -> Option>> { None } /// # } /// ``` /// @@ -157,7 +157,7 @@ pub trait Transition /// implementation details of the `Automaton`. Unfortunately, that isn't possible, in this case, because the `Mode` /// trait cannot be made into an object, and therefore cannot be boxed. /// - fn invoke(self : Box, mode : A) -> Box>; + fn invoke(self : Box, mode : A) -> Box>; } impl Transition for T @@ -166,7 +166,7 @@ impl Transition for T A : Mode, B : Mode, { - fn invoke(self : Box, mode : A) -> Box> { + fn invoke(self : Box, mode : A) -> Box> { // Call the transition function and wrap the result with a ModeWrapper. Box::new(ModeWrapper::::new((self)(mode))) }