Trait lexopt::ValueExt

source ·
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:

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

Required Methods§

source

fn parse<T: FromStr>(&self) -> Result<T, Error>
where T::Err: Into<Box<dyn Error + Send + Sync + 'static>>,

Decode the value and parse it using FromStr.

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

source

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>>,

Decode the value and parse it using a custom function.

source

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.

Implementations on Foreign Types§

source§

impl ValueExt for OsString

source§

fn parse<T: FromStr>(&self) -> Result<T, Error>
where T::Err: Into<Box<dyn Error + Send + Sync + 'static>>,

source§

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>>,

source§

fn string(self) -> Result<String, Error>

Implementors§