From 41cc79db2ac330deb1204c27e873b08294ea8a3d Mon Sep 17 00:00:00 2001 From: RA <70325462+RAprogramm@users.noreply.github.com> Date: Thu, 11 Sep 2025 14:33:40 +0700 Subject: [PATCH] docs: explain config error mapping --- src/convert/config.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) 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)); + } +}