Finite state machines in rust; bendns fork to add types.
-rw-r--r--CHANGELOG.md2
-rw-r--r--src/lib.rs8
2 files changed, 9 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2248ebb..f0bfe65 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog][keepachangelog], and this project
adheres to [Semantic Versioning][semver].
## [Unreleased]
+### Added
+* Add the `from_state` method to start the machine from any given state.
## [0.3.0] - 2019-05-22
### Changed
diff --git a/src/lib.rs b/src/lib.rs
index 991df4a..16b189a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -149,8 +149,14 @@ where
/// Create a new instance of this wrapper which encapsulates the initial
/// state.
pub fn new() -> Self {
+ Self::from_state(T::INITIAL_STATE)
+ }
+
+ /// Create a new instance of this wrapper which encapsulates the given
+ /// state.
+ pub fn from_state(state: T::State) -> Self {
Self {
- state: T::INITIAL_STATE,
+ state
}
}