diff --git a/src/convert/config.rs b/src/convert/config.rs index bf37514..e88ae5a 100644 --- a/src/convert/config.rs +++ b/src/convert/config.rs @@ -1,3 +1,18 @@ +//! Convert [`config::ConfigError`] into [`AppError`], +//! producing [`AppErrorKind::Config`]. +//! +//! Enabled with the `config` feature. +//! +//! ## Example +//! +//! ```rust,ignore +//! use config::ConfigError; +//! use masterror::{AppError, AppErrorKind}; +//! +//! let err = ConfigError::Message("missing key".into()); +//! let app_err: AppError = err.into(); +//! assert!(matches!(app_err.kind, AppErrorKind::Config)); +//! ``` #[cfg(feature = "config")] use config::ConfigError; @@ -5,8 +20,23 @@ use config::ConfigError; use crate::AppError; #[cfg(feature = "config")] +#[cfg_attr(docsrs, doc(cfg(feature = "config")))] impl From for AppError { fn from(err: ConfigError) -> Self { AppError::config(err.to_string()) } } + +#[cfg(all(test, feature = "config"))] +mod tests { + use config::ConfigError; + + use crate::{AppError, AppErrorKind}; + + #[test] + fn maps_to_config_kind() { + let err = ConfigError::Message("dummy".into()); + let app_err = AppError::from(err); + assert!(matches!(app_err.kind, AppErrorKind::Config)); + } +}