pub trait ArgV: Sealed {
// Required methods
fn into_argv(self) -> Cow<'static, str>;
fn as_argv(&self) -> Cow<'_, str>;
}Expand description
Trait for types that can be converted into strings for use as command-line arguments.
This trait is implemented for common string types and enables the library to work with different argument representations. It is sealed and cannot be implemented outside of this crate.
Borrowed implementations are bounded by 'static so they can flow through the
parser as Cow::Borrowed without allocation. This makes the crate a good fit
for sources like the argv crate, which yields
&'static OsStr. Owned types (String, OsString) have no lifetime constraint.
§Implementations
&'static str- String slices (zero-copy)String- Owned strings (zero-copy, takes ownership)&'static CStr- C-style nul-terminated strings (zero-copy when valid UTF-8)OsString- Platform-native strings (zero-copy when valid UTF-8; requiresstd)&'static OsStr- Borrowed platform-native strings (zero-copy when valid UTF-8; requiresstd)
Required Methods§
Sourcefn into_argv(self) -> Cow<'static, str>
fn into_argv(self) -> Cow<'static, str>
Converts self into a Cow<'static, str>.
For OsString/OsStr/CStr, invalid UTF-8 sequences are replaced with the
Unicode replacement character (U+FFFD), which forces an allocation. Valid
UTF-8 input is passed through without copying.
Sourcefn as_argv(&self) -> Cow<'_, str>
fn as_argv(&self) -> Cow<'_, str>
Non-destructively view self as a &str.
Used internally to inspect an argument (e.g. to decide whether it begins with -)
without consuming it, so that non-option arguments can be left in place for
Getopt::remaining.
For OsStr/OsString/CStr, invalid UTF-8 sequences are replaced with the
Unicode replacement character (U+FFFD).