From 183ee2accc06680be470911aa0d1f6744e3e9ba7 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Thu, 13 Dec 2018 13:39:16 +0100 Subject: [PATCH] fix(core): Ensure FSM state can be created from backend state ref The action interpreter can not own the backend state, hence it must be possible to create the required state from a reference to the backend's state. --- finito-core/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/finito-core/src/lib.rs b/finito-core/src/lib.rs index 0dda30ae9..517bfad2b 100644 --- a/finito-core/src/lib.rs +++ b/finito-core/src/lib.rs @@ -166,7 +166,7 @@ pub trait FSM where Self: Sized { /// `act` interprets and executes FSM actions. This is the only /// part of an FSM in which side-effects are allowed. - fn act(Self::Action, Self::State) -> Result, Self::Error>; + fn act(Self::Action, &Self::State) -> Result, Self::Error>; } /// This function is the primary function used to advance a state @@ -208,7 +208,7 @@ pub fn advance(state: S, event: S::Event) -> (S, Vec) { /// state type which can be used to track application state that must /// be made available to action handlers, for example to pass along /// database connections. -pub trait FSMBackend { +pub trait FSMBackend { /// Key type used to identify individual state machines in this /// backend. /// @@ -235,9 +235,9 @@ pub trait FSMBackend { /// **Note**: Whether actions are automatically executed depends /// on the backend used. Please consult the backend's /// documentation for details. - fn advance(&self, key: Self::Key, event: F::Event) -> Result + fn advance<'a, F: FSM>(&'a self, key: Self::Key, event: F::Event) -> Result where F: FSM + Serialize + DeserializeOwned, - F::State: From, + F::State: From<&'a S>, F::Event: Serialize + DeserializeOwned, F::Action: Serialize + DeserializeOwned; }