rstm_tape/
error.rs

1/*
2    Appellation: error <module>
3    Contrib: FL03 <jo3mccain@icloud.com>
4*/
5//! This module defines the custom error type for handling various tape-related errors.
6#[cfg(feature = "alloc")]
7use alloc::boxed::Box;
8
9/// A type alias for a [`Result`](core::result::Result) that uses the custom [`Error`] type
10pub type Result<T> = core::result::Result<T, Error>;
11
12/// The [`Error`] type enumerates various errors that can occur in tape operations
13#[derive(Debug, thiserror::Error)]
14pub enum Error {
15    #[error("attempted to read from an empty tape")]
16    EmptyTape,
17    #[error("attempted to write to an empty tape")]
18    WriteToEmptyTape,
19    #[error("invalid operation: {0}")]
20    InvalidOperation(&'static str),
21    #[error(transparent)]
22    CoreError(#[from] rstm_core::Error),
23    #[error(transparent)]
24    StateError(#[from] rstm_state::StateError),
25}
26
27#[cfg(feature = "alloc")]
28impl From<Error> for rstm_core::Error {
29    fn from(err: Error) -> Self {
30        match err {
31            Error::CoreError(e) => e,
32            e => rstm_core::Error::BoxError(Box::new(e)),
33        }
34    }
35}