use std::error::Error;
use std::fmt::Debug;
use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::Result as FmtResult;
#[must_use]
pub struct FixtureError {
message: String,
source: Option<Box<dyn Error + Send + Sync + 'static>>,
}
impl FixtureError {
#[inline]
pub fn new(message: impl Into<String>) -> Self {
Self {
message: message.into(),
source: None,
}
}
#[inline]
pub fn with_source(message: impl Into<String>, source: impl Error + Send + Sync + 'static) -> Self {
Self {
message: message.into(),
source: Some(Box::new(source)),
}
}
}
impl Debug for FixtureError {
#[inline]
fn fmt(&self, formatter: &mut Formatter<'_>) -> FmtResult {
formatter
.debug_struct("FixtureError")
.field("message", &self.message)
.finish()
}
}
impl Display for FixtureError {
#[inline]
fn fmt(&self, formatter: &mut Formatter<'_>) -> FmtResult {
formatter.write_str(&self.message)
}
}
impl Error for FixtureError {
#[inline]
fn source(&self) -> Option<&(dyn Error + 'static)> {
self.source.as_deref().map(|error| error as &(dyn Error + 'static))
}
}
pub type FixtureResult<T> = Result<T, FixtureError>;