/// Loads a value from the provided config source.
/// The source is expected to be a valid JSON5 document.
Loads a value from the provided config source.
The source is expected to be a valid JSON5 document.
Loads a value from the provided config source . The source is expected to be a valid JSON5 document .
pub fn load<T: DeserializeOwned + Default + ConfigValidate>(&self) -> Result<T, ConfigError> {
        let cfg_str = match &self {
            ConfigSource::Default => return Ok(Default::default()),
            ConfigSource::Literal(literal) => literal.clone(),
            ConfigSource::StdIn => {
                use std::io::Read;
                let mut buf = String::new();
                std::io::stdin()
                    .read_to_string(&mut buf)
                    .map_err(|io_error| ConfigError::IoError {
                        source: self.clone(),
                        io_error,
                    })?;
                buf
            }
            ConfigSource::File(path) => {
                fs::read_to_string(&path).map_err(|io_error| ConfigError::IoError {
                    source: self.clone(),
                    io_error,
                })?
            }
        };
        let cfg = json5::from_str::<T>(&cfg_str).map_err(|err| ConfigError::ParseError {
            source: self.clone(),
            message: err.to_string(),
        })?;
        cfg.validate().map_err(|err| ConfigError::ValidationError {
            source: self.clone(),
            message: err,
        })
    }
pub fn load < T : DeserializeOwned + Default + ConfigValidate > ( & self ) -> Result < T , ConfigError > { let cfg_str = match & self { ConfigSource :: Default => return Ok ( Default :: default ( ) ) , ConfigSource :: Literal ( literal ) => literal . clone ( ) , ConfigSource :: StdIn => { use std :: io :: Read ; let mut buf = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut buf ) . map_err ( | io_error | ConfigError :: IoError { source : self . clone ( ) , io_error , } ) ? ; buf } ConfigSource :: File ( path ) => { fs :: read_to_string ( & path ) . map_err ( | io_error | ConfigError :: IoError { source : self . clone ( ) , io_error , } ) ? } } ; let cfg = json5 :: from_str :: < T > ( & cfg_str ) . map_err ( | err | ConfigError :: ParseError { source : self . clone ( ) , message : err . to_string ( ) , } ) ? ; cfg . validate ( ) . map_err ( | err | ConfigError :: ValidationError { source : self . clone ( ) , message : err , } ) }
Loads a value from the provided config source.
Loads a value from the provided config source .
&self