Trait lexopt::ValueExt

source ·
pub trait ValueExt: Sealed {
    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:

If parsing fails the error will be wrapped in lexopt’s own Error type.

Required Methods§

Decode the value and parse it using FromStr.

This will fail if the value is not valid unicode or if the subsequent parsing fails.

Decode the value and parse it using a custom function.

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.

Implementations on Foreign Types§

Implementors§