pub trait ValueExt: Sealed {
// Required methods
fn parse<T: FromStr>(&self) -> Result<T, Error>
where T::Err: Into<Box<dyn Error + Send + Sync + 'static>>;
fn parse_with<F, T, E>(&self, func: F) -> Result<T, Error>
where F: FnOnce(&str) -> Result<T, E>,
E: Into<Box<dyn Error + Send + Sync + 'static>>;
fn string(self) -> Result<String, Error>;
}Expand description
An optional extension trait with methods for parsing OsStrings.
They may fail in two cases:
- The value cannot be decoded because it’s invalid unicode
(
Error::NonUnicodeValue) - The value can be decoded, but parsing fails (
Error::ParsingFailed)
If parsing fails the error will be wrapped in lexopt’s own Error type.
Required Methods§
sourcefn parse<T: FromStr>(&self) -> Result<T, Error>
fn parse<T: FromStr>(&self) -> Result<T, Error>
Decode the value and parse it using FromStr.
This will fail if the value is not valid unicode or if the subsequent parsing fails.
sourcefn parse_with<F, T, E>(&self, func: F) -> Result<T, Error>
fn parse_with<F, T, E>(&self, func: F) -> Result<T, Error>
Decode the value and parse it using a custom function.
sourcefn string(self) -> Result<String, Error>
fn string(self) -> Result<String, Error>
Convert the OsString into a String if it’s valid Unicode.
This is like OsString::into_string but returns an
Error::NonUnicodeValue on error instead of the original OsString.
This makes it easier to propagate the failure with libraries like
anyhow.
Object Safety§
This trait is not object safe.