use thiserror::Error;
#[derive(Debug, Error)]
pub enum Error {
#[error("configuration error: {0}")]
Configuration(String),
#[error("diff error: {0}")]
Diff(String),
#[error(transparent)]
Other(#[from] Box<dyn std::error::Error + Send + Sync>),
}
impl Error {
pub fn config(msg: impl Into<String>) -> Self {
Self::Configuration(msg.into())
}
pub fn diff(msg: impl Into<String>) -> Self {
Self::Diff(msg.into())
}
}
pub type Result<T> = std::result::Result<T, Error>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn configuration_error_message() {
assert_eq!(
Error::config("snippet_max must be > 0").to_string(),
"configuration error: snippet_max must be > 0"
);
}
#[test]
fn diff_error_message() {
assert_eq!(
Error::diff("LCS computation failed").to_string(),
"diff error: LCS computation failed"
);
}
#[test]
fn result_ok() {
let r: Result<i32> = Ok(1);
assert!(matches!(r, Ok(1)));
}
}