[−][src]Trait go_flag::FlagValue
Values that can be parsed from a string.
This is similar to FromStr
, but different in the following ways:
- A source string can be
None
, indicating a boolean flag with no argument. - A source string is given as
&OsStr
. - The behavior is meant to be compatible with Go's
strconv
by default.
Common Formats
Boolean
bool
- It can accept a boolean flag:
-f
instead of-f=true
. 0
,f
,F
,false
,False
, andFALSE
are considered false.1
,t
,T
,true
,True
, andTRUE
are considered true.- Other values are treated as invalid.
Warnings:
0
,1
,f
,t
,F
,T
,False
,True
,FALSE
, andTRUE
are considered incompatible.
Unsigned integer
u8
, u16
, u32
, u64
, u128
, usize
- Sign (
-
or+
) is not allowed. - It may have an optional radix prefix:
0x
,0o
,0
, or0b
. It's case-insensitive. - Unless it's
0
, it must have at least one digit, except the radix prefix. - It may have optional underscores between the radix prefix and a digit or between digits. Underscores can't be consecutive.
Warnings:
- radix prefixes, including
0
, are considered incompatible.- Exception: values from 0 to 7 are unambiguous, so considered compatible.
- underscores are considered incompatible.
Signed integer
i8
, i16
, i32
, i64
, i128
, isize
- Sign (
-
or+
) is allowed at the beginning of the string. - Otherwise same as unsigned integers.
Warnings:
- radix prefixes, including
0
, are considered incompatible.- Exception: values from -7 to 7 are unambiguous, so considered compatible.
- underscores are considered incompatible.
Floating point number
f32
, f64
Not yet implemented
UTF-8 String
String
- Any UTF-8 strings are allowed on unix-like platforms.
- Any UTF-16 strings are allowed on Windows.
No warning is defined.
OS-defined String
OsString
, PathBuf
- Anything is allowed.
No warning is defined.
Required methods
fn parse(
value: Option<&OsStr>,
warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
value: Option<&OsStr>,
warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
Provided methods
fn is_bool_flag() -> bool
Indicates whether the flag is a boolean flag.
For most types, this is false
.
Implementations on Foreign Types
impl FlagValue for OsString
[src]
fn parse(
value: Option<&OsStr>,
_warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
[src]
value: Option<&OsStr>,
_warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
impl FlagValue for PathBuf
[src]
fn parse(
value: Option<&OsStr>,
_warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
[src]
value: Option<&OsStr>,
_warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
impl FlagValue for String
[src]
fn parse(
value: Option<&OsStr>,
_warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
[src]
value: Option<&OsStr>,
_warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
impl FlagValue for bool
[src]
fn is_bool_flag() -> bool
[src]
fn parse(
value: Option<&OsStr>,
warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
[src]
value: Option<&OsStr>,
warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
impl FlagValue for i8
[src]
fn parse(
value: Option<&OsStr>,
warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
[src]
value: Option<&OsStr>,
warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
impl FlagValue for i16
[src]
fn parse(
value: Option<&OsStr>,
warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
[src]
value: Option<&OsStr>,
warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
impl FlagValue for i32
[src]
fn parse(
value: Option<&OsStr>,
warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
[src]
value: Option<&OsStr>,
warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
impl FlagValue for i64
[src]
fn parse(
value: Option<&OsStr>,
warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
[src]
value: Option<&OsStr>,
warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
impl FlagValue for i128
[src]
fn parse(
value: Option<&OsStr>,
warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
[src]
value: Option<&OsStr>,
warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
impl FlagValue for isize
[src]
fn parse(
value: Option<&OsStr>,
warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
[src]
value: Option<&OsStr>,
warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
impl FlagValue for u8
[src]
fn parse(
value: Option<&OsStr>,
warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
[src]
value: Option<&OsStr>,
warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
impl FlagValue for u16
[src]
fn parse(
value: Option<&OsStr>,
warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
[src]
value: Option<&OsStr>,
warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
impl FlagValue for u32
[src]
fn parse(
value: Option<&OsStr>,
warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
[src]
value: Option<&OsStr>,
warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
impl FlagValue for u64
[src]
fn parse(
value: Option<&OsStr>,
warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
[src]
value: Option<&OsStr>,
warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
impl FlagValue for u128
[src]
fn parse(
value: Option<&OsStr>,
warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
[src]
value: Option<&OsStr>,
warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
impl FlagValue for usize
[src]
fn parse(
value: Option<&OsStr>,
warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>
[src]
value: Option<&OsStr>,
warnings: Option<&mut Vec<FlagWarning>>
) -> Result<Self, FlagParseError>