pub enum ValueRef<'a> {
String(Cow<'a, str>),
Float(f64),
Int(i64),
Buffer(Cow<'a, [u8]>),
Empty,
Boolean(bool),
}
Expand description
A borrowed parameter value that may be a string, a number, or empty. It is intended to
be paired with the ParamValue
trait.
The owned equivalent of this type is Value
.
Variants§
String(Cow<'a, str>)
A text value of arbitrary length
Float(f64)
A floating point number
Int(i64)
A integral number
Buffer(Cow<'a, [u8]>)
Arbitrary binary data
Empty
No value specified
Boolean(bool)
A true/false value
Implementations§
Source§impl<'a> ValueRef<'a>
impl<'a> ValueRef<'a>
Sourcepub fn new(s: &'a str) -> ValueRef<'a>
pub fn new(s: &'a str) -> ValueRef<'a>
Convert a string value into a precise value type by trying successive types to parse, defaulting to storing the string as-is.
pub fn coerce_bool(&mut self) -> Result<(), ParamValueParseError>
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 ValueRef::Empty
Sourcepub fn coerce_buffer(&mut self) -> Result<(), ParamValueParseError>
pub fn coerce_buffer(&mut self) -> Result<(), ParamValueParseError>
Store the value as a byte buffer
Trait Implementations§
Source§impl ParamValue for ValueRef<'_>
impl ParamValue for ValueRef<'_>
Source§fn is_f64(&self) -> bool
fn is_f64(&self) -> bool
Check if the value is a floating point
number explicitly. An integral number might
still be usable as a floating point number
Source§fn is_str(&self) -> bool
fn is_str(&self) -> bool
Check if the value is stored as an explicit string.
All variants can be coerced to a string.
Source§fn is_boolean(&self) -> bool
fn is_boolean(&self) -> bool
Check if the value is a boolean
Source§fn to_buffer(&self) -> Result<Cow<'_, [u8]>, ParamValueParseError>
fn to_buffer(&self) -> Result<Cow<'_, [u8]>, ParamValueParseError>
Get the value as a byte buffer, if possible. Read more
Source§fn parse<T>(&self) -> Result<T, <T as FromStr>::Err>where
T: FromStr,
fn parse<T>(&self) -> Result<T, <T as FromStr>::Err>where
T: FromStr,
Convert the value’s string representation to
T
if possibleSource§fn as_bytes(&self) -> Cow<'_, [u8]>
fn as_bytes(&self) -> Cow<'_, [u8]>
Convert the value to a byte string, the bytes
of the string representation.
Source§fn is_numeric(&self) -> bool
fn is_numeric(&self) -> bool
Check if the value is of either numeric type.
Source§impl<'a> PartialOrd for ValueRef<'a>
impl<'a> PartialOrd for ValueRef<'a>
impl Eq for ValueRef<'_>
impl<'a> StructuralPartialEq for ValueRef<'a>
Auto Trait Implementations§
impl<'a> Freeze for ValueRef<'a>
impl<'a> RefUnwindSafe for ValueRef<'a>
impl<'a> Send for ValueRef<'a>
impl<'a> Sync for ValueRef<'a>
impl<'a> Unpin for ValueRef<'a>
impl<'a> UnwindSafe for ValueRef<'a>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.