pub trait FromArg: Sized {
const CHOICES: &'static [&'static str] = _;
const HINT: Hint = crate::complete::Hint::Nothing;
// Required method
fn from_arg(value: &BStr) -> Result<Self, BoxError>;
}Expand description
A type a flag’s value can be converted into.
Values arrive as bytes borrowed from the command line. Conversion is the only place a value can fail, so a command line that is not valid UTF-8 still parses — flags still match — and only a value that is actually converted to text can be rejected for it.
For a type that is FromStr, Parsed<T> needs no
impl. Otherwise:
use winnow_args::error::BoxError;
use winnow_args::{BStr, FromArg};
/// `WIDTHxHEIGHT`.
struct Size(u32, u32);
impl FromArg for Size {
fn from_arg(value: &BStr) -> Result<Self, BoxError> {
let (w, h) = std::str::from_utf8(value)?
.split_once('x')
.ok_or("expected WIDTHxHEIGHT")?;
Ok(Size(w.parse()?, h.parse()?))
}
}
let Size(w, h) = Size::from_arg(BStr::new("80x24")).unwrap();
assert_eq!((w, h), (80, 24));Provided Associated Constants§
Sourceconst CHOICES: &'static [&'static str] = _
const CHOICES: &'static [&'static str] = _
The values accepted, when there is a fixed set: help lists them as
[possible values: …]. Empty by default; #[derive(ValueEnum)] fills
it with each visible variant’s name.
Sourceconst HINT: Hint = crate::complete::Hint::Nothing
const HINT: Hint = crate::complete::Hint::Nothing
What the value is, for the shell that completes it, when a field
states no hint. Nothing a shell knows by default: a number, an
address, a type of the program. A PathBuf, a String and an
OsString are a file: a word is one more often than not, and a shell
that offers files stops no other word from being typed.
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".