errors.rs
688 B · rust · 27 lines
1use std::error::Error;2use std::fmt;34/// The one error type of the crate.5#[derive(Debug)]6pub enum MrlyError {7 /// A value that broke a rule, carrying the message.8 Value(String),9}1011impl fmt::Display for MrlyError {12 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {13 match self {14 MrlyError::Value(message) => write!(f, "{message}"),15 }16 }17}1819impl Error for MrlyError {}2021/// The crate's result, erring with MrlyError.22pub type Result<T> = std::result::Result<T, MrlyError>;2324/// Wraps a message in an Err of the value variant.25pub fn value_error<T>(message: impl Into<String>) -> Result<T> {26 Err(MrlyError::Value(message.into()))27}