mirror of
https://github.com/OMGeeky/confique.git
synced 2026-02-23 15:38:30 +01:00
Move TryFromError from generated code into main crate
There is not really a point in generating this type for every invocation. Also reduces the number of things magically generated.
This commit is contained in:
29
src/lib.rs
29
src/lib.rs
@@ -2,3 +2,32 @@
|
||||
pub use confique_macro::config as config;
|
||||
|
||||
pub use serde;
|
||||
|
||||
|
||||
use std::fmt;
|
||||
|
||||
|
||||
/// Error for the `TryFrom` conversion from raw types to the main types.
|
||||
///
|
||||
/// This error is returned when a required value is `None` in the raw type.
|
||||
#[derive(Clone)]
|
||||
pub struct TryFromError {
|
||||
/// This is only public so that macro generated code can created instances
|
||||
/// of this type.
|
||||
#[doc(hidden)]
|
||||
pub path: &'static str,
|
||||
}
|
||||
|
||||
impl fmt::Display for TryFromError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
std::write!(f, "required configuration value is missing: '{}'", self.path)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for TryFromError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Display::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for TryFromError {}
|
||||
|
||||
Reference in New Issue
Block a user