Skip to main content

statum_core/
lib.rs

1//! Core error and result types shared by Statum crates.
2
3/// Errors returned by Statum runtime helpers.
4#[derive(Debug)]
5pub enum Error {
6    /// Returned when a runtime check determines the current state is invalid.
7    InvalidState,
8}
9
10/// Convenience result alias used by Statum APIs.
11///
12/// # Example
13///
14/// ```
15/// fn ensure_ready(ready: bool) -> statum_core::Result<()> {
16///     if ready {
17///         Ok(())
18///     } else {
19///         Err(statum_core::Error::InvalidState)
20///     }
21/// }
22///
23/// assert!(ensure_ready(true).is_ok());
24/// assert!(ensure_ready(false).is_err());
25/// ```
26pub type Result<T> = core::result::Result<T, Error>;
27
28impl<T> From<Error> for core::result::Result<T, Error> {
29    fn from(val: Error) -> Self {
30        Err(val)
31    }
32}
33
34impl core::fmt::Display for Error {
35    fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::result::Result<(), core::fmt::Error> {
36        write!(fmt, "{self:?}")
37    }
38}
39
40impl std::error::Error for Error {}