1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
use std::fmt::{Display, Error, Formatter}; #[derive(Debug)] pub enum ConfigParseError { MissingSection(String), MissingComponent { section: String, component: String, }, InvalidComponent { section: String, expected_component: String, actual_component: String, }, InvalidComponentValue { section: String, component: String, value: String, }, } impl Display for ConfigParseError { fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error> { write!(formatter, "Parse error. ")?; match *self { ConfigParseError::MissingSection(ref section) => { write!(formatter, "Missing section = {}", section) } ConfigParseError::MissingComponent { ref section, ref component, } => write!( formatter, "Missing component = {} in section = {}", component, section ), ConfigParseError::InvalidComponent { ref section, ref expected_component, ref actual_component, } => write!( formatter, "Invalid component = {} in section = {}. Expected = {}", actual_component, section, expected_component ), ConfigParseError::InvalidComponentValue { ref section, ref component, ref value, } => write!( formatter, "Invalid component value = {} for component = {} in section = {}", value, component, section ), } } }