use super::ParseError; pub trait FromStrings: Sized { fn from_strings>(s: I) -> Result; } /// Same as [FromStrings] but can pass a hint to the function which can help /// in some determinations (e.g. passing in the path of the attribute for /// parsing a [crate::hlwm::Attribute] so it can use the path to determine the /// type of the attribute) pub trait FromStringsHint: Sized { fn from_strings_hint>(s: I, hint: Hint) -> Result; } pub trait FromCommandArgs: Sized { fn from_command_args, I: Iterator>( command: &str, args: I, ) -> Result; } pub trait ToOption: Sized { fn to_option(self) -> Option; } impl ToOption for Vec { fn to_option(self) -> Option { match self.is_empty() { false => Some(self), true => None, } } } impl ToOption for &str { fn to_option(self) -> Option { match self.is_empty() { false => Some(self), true => None, } } } impl ToOption for String { fn to_option(self) -> Option { match self.is_empty() { false => Some(self), true => None, } } } pub trait Flip { type Target; fn flip(self) -> Self::Target; } impl Flip for Option> { type Target = Result, E>; fn flip(self) -> Self::Target { match self { Some(r) => r.map(Some), None => Self::Target::Ok(None), } } }