pub enum Value {
String(String),
Float(f64),
Int(i64),
Buffer(Box<[u8]>),
Boolean(bool),
Empty,
List(Box<[Value]>),
}Expand description
An owned parameter value that may be a string, a number, or empty. It is intended to
be paired with the ParamValue trait.
The borrowed equivalent of this type is ValueRef.
Variants§
String(String)
A text value of arbitrary length
Float(f64)
A floating point number
Int(i64)
A integral number
Buffer(Box<[u8]>)
Arbitrary binary data
Boolean(bool)
true/false value
Empty
No value specified
List(Box<[Value]>)
A list of heterogenous Value
Implementations§
Source§impl Value
impl Value
Sourcepub fn new(s: String) -> Self
pub fn new(s: String) -> Self
Convert a string value into a precise value type by trying successive types to parse, defaulting to storing the string as-is.
This takes ownership of the string. To coerce from a borrowed
string see Value::wrap.
Sourcepub fn wrap(s: &str) -> Self
pub fn wrap(s: &str) -> Self
Convert a borrowed string value into a precise value type by trying successive types to parse, defaulting to storing the string as-is.
This only makes a copy of the string if it cannot be parsed into a numeric type.
pub fn is_empty(&self) -> bool
pub fn is_i64(&self) -> bool
pub fn is_f64(&self) -> bool
pub fn is_buffer(&self) -> bool
pub fn is_str(&self) -> bool
pub fn is_list(&self) -> bool
Sourcepub fn coerce_f64(&mut self) -> Result<(), ParamValueParseError>
pub fn coerce_f64(&mut self) -> Result<(), ParamValueParseError>
Store the value as a floating point number
Sourcepub fn coerce_i64(&mut self) -> Result<(), ParamValueParseError>
pub fn coerce_i64(&mut self) -> Result<(), ParamValueParseError>
Store the value as an integer
Sourcepub fn coerce_str(&mut self) -> Result<(), ParamValueParseError>
pub fn coerce_str(&mut self) -> Result<(), ParamValueParseError>
Store the value as a string
Sourcepub fn coerce_empty(&mut self)
pub fn coerce_empty(&mut self)
Discard the value, leaving this value Value::Empty
Sourcepub fn coerce_buffer(&mut self) -> Result<(), ParamValueParseError>
pub fn coerce_buffer(&mut self) -> Result<(), ParamValueParseError>
Store the value as a byte buffer
Sourcepub fn coerce_bool(&mut self) -> Result<(), ParamValueParseError>
pub fn coerce_bool(&mut self) -> Result<(), ParamValueParseError>
Store the value as a boolean
Sourcepub fn coerce_list(&mut self) -> Result<(), ParamValueParseError>
pub fn coerce_list(&mut self) -> Result<(), ParamValueParseError>
Store the value as a list
Sourcepub fn parse<T: FromStr>(&self) -> Result<T, T::Err>
pub fn parse<T: FromStr>(&self) -> Result<T, T::Err>
Convert the value to a text string and then try to parse it into T.
If the type is one of the common numeric types, prefer one of the provided
methods with a to_ prefix as they avoid the string conversions.
pub fn to_bool(&self) -> Result<bool, ParamValueParseError>
pub fn to_f64(&self) -> Result<f64, ParamValueParseError>
pub fn to_i64(&self) -> Result<i64, ParamValueParseError>
pub fn to_str(&self) -> Cow<'_, str>
pub fn to_buffer(&self) -> Result<Cow<'_, [u8]>, ParamValueParseError>
pub fn as_ref(&self) -> ValueRef<'_>
Trait Implementations§
impl Eq for Value
Source§impl FromStr for Value
A Value can be parsed from a string infallibly, even though an error type
is given, but unless one of the numerical parsers succeeds, the stored value will
just be a string.
impl FromStr for Value
A Value can be parsed from a string infallibly, even though an error type
is given, but unless one of the numerical parsers succeeds, the stored value will
just be a string.
Source§impl ParamValue for Value
impl ParamValue for Value
Source§fn is_f64(&self) -> bool
fn is_f64(&self) -> bool
Source§fn is_str(&self) -> bool
fn is_str(&self) -> bool
Source§fn to_buffer(&self) -> Result<Cow<'_, [u8]>, ParamValueParseError>
fn to_buffer(&self) -> Result<Cow<'_, [u8]>, ParamValueParseError>
Source§fn parse<T: FromStr>(&self) -> Result<T, T::Err>
fn parse<T: FromStr>(&self) -> Result<T, T::Err>
T if possible