Finite state machines in rust; bendns fork to add types.
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs
index d750135..e8b78bb 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,4 +1,3 @@
-#![no_std]
//! A framework for building finite state machines in Rust
//!
//! The `rust-fsm` crate provides a simple and universal framework for building
@@ -28,6 +27,14 @@
//! * A Moore machine by providing an output function that do not depend on the
//! provided inputs.
//!
+//! # Usage in `no_std` environments
+//!
+//! This library has the feature named `std` which is enabled by default. You
+//! may want to import this library as
+//! `rust-fsm = { version = "0.5", default-features = false }` to use it in a
+//! `no_std` environment. This only affects error types (the `Error` trait is
+//! only available in `std`).
+//!
//! # Use
//!
//! Initially this library was designed to build an easy to use DSL for defining
@@ -113,7 +120,11 @@
//!
//! [repo]: https://github.com/eugene-babichenko/rust-fsm/blob/master/tests/circuit_breaker.rs
+#![cfg_attr(not(feature = "std"), no_std)]
+
use core::fmt;
+#[cfg(feature = "std")]
+use std::error::Error;
#[doc(hidden)]
pub use rust_fsm_dsl::*;
@@ -209,3 +220,10 @@ impl fmt::Display for TransitionImpossibleError {
)
}
}
+
+#[cfg(feature = "std")]
+impl Error for TransitionImpossibleError {
+ fn source(&self) -> Option<&(dyn Error + 'static)> {
+ None
+ }
+}