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:
Lukas Kalbertodt
2021-04-29 18:41:17 +02:00
parent 537a8b7725
commit 1ae45a3e7c
2 changed files with 39 additions and 36 deletions

View File

@@ -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 {}