Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/convert/config.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,42 @@
//! 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;

#[cfg(feature = "config")]
use crate::AppError;

#[cfg(feature = "config")]
#[cfg_attr(docsrs, doc(cfg(feature = "config")))]
impl From<ConfigError> 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));
}
}
Loading