pub enum Value {
Str(String),
Int(i64),
Float(f64),
Bool(bool),
}Expand description
Represents a typed value parsed from command-line arguments.
Supports common primitive types used in CLI applications.
§Examples
let str_val = Value::Str("hello".to_string());
let int_val = Value::Int(42);
let float_val = Value::Float(3.14);
let bool_val = Value::Bool(true);Variants§
Str(String)
A string value
Int(i64)
An integer value (64-bit signed)
Float(f64)
A floating-point value (64-bit)
Bool(bool)
A boolean value
Implementations§
Source§impl Value
impl Value
Sourcepub fn replace_with_expected_value(&mut self, new_value: &str) -> Result<Value>
pub fn replace_with_expected_value(&mut self, new_value: &str) -> Result<Value>
Replaces the current value with a new value parsed from a string.
This method attempts to parse the input string according to the expected type and updates the value in place if successful.
§Arguments
new_value- The string representation of the new value
§Returns
Ok(Value)- A clone of the updated valueErr(FliError)- If parsing fails
§Examples
let mut val = Value::Int(0);
val.replace_with_expected_value("42").unwrap();
assert_eq!(val, Value::Int(42));
let mut val = Value::Bool(false);
val.replace_with_expected_value("yes").unwrap();
assert_eq!(val, Value::Bool(true));Sourcepub fn from_str_with_type(template: &Value, input: &str) -> Result<Value>
pub fn from_str_with_type(template: &Value, input: &str) -> Result<Value>
Creates a new Value from a string, attempting to parse it according to the type.
This is similar to replace_with_expected_value but creates a new value instead
of modifying an existing one.
§Arguments
template- A template value indicating the expected typeinput- The string to parse
§Returns
Ok(Value)- The parsed valueErr(FliError)- If parsing fails
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Value
impl RefUnwindSafe for Value
impl Send for Value
impl Sync for Value
impl Unpin for Value
impl UnwindSafe for Value
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more