Enum ValueRef

Source
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>

Source

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.

Source

pub const fn wrap(s: &'a str) -> ValueRef<'a>

Create a string ValueRef

Source

pub fn coerce_bool(&mut self) -> Result<(), ParamValueParseError>

Source

pub fn coerce_f64(&mut self) -> Result<(), ParamValueParseError>

Store the value as a floating point number

Source

pub fn coerce_i64(&mut self) -> Result<(), ParamValueParseError>

Store the value as an integer

Source

pub fn coerce_str(&mut self) -> Result<(), ParamValueParseError>

Store the value as a string

Source

pub fn coerce_empty(&mut self)

Discard the value, leaving this value ValueRef::Empty

Source

pub fn coerce_buffer(&mut self) -> Result<(), ParamValueParseError>

Store the value as a byte buffer

Trait Implementations§

Source§

impl<'a> AsRef<ValueRef<'a>> for ParamCow<'a>

Source§

fn as_ref(&self) -> &ValueRef<'a>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'a> Clone for ValueRef<'a>

Source§

fn clone(&self) -> ValueRef<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for ValueRef<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'a> Default for ValueRef<'a>

Source§

fn default() -> ValueRef<'a>

Returns the “default value” for a type. Read more
Source§

impl Display for ValueRef<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'a> From<&'a Value> for ValueRef<'a>

Source§

fn from(value: &'a Value) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<&f32> for ValueRef<'a>

Source§

fn from(value: &f32) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<&f64> for ValueRef<'a>

Source§

fn from(value: &f64) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<&i16> for ValueRef<'a>

Source§

fn from(value: &i16) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<&i32> for ValueRef<'a>

Source§

fn from(value: &i32) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<&i64> for ValueRef<'a>

Source§

fn from(value: &i64) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<&i8> for ValueRef<'a>

Source§

fn from(value: &i8) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<&'a str> for ValueRef<'a>

Source§

fn from(value: &'a str) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<&u16> for ValueRef<'a>

Source§

fn from(value: &u16) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<&u32> for ValueRef<'a>

Source§

fn from(value: &u32) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<&u64> for ValueRef<'a>

Source§

fn from(value: &u64) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<&u8> for ValueRef<'a>

Source§

fn from(value: &u8) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<&usize> for ValueRef<'a>

Source§

fn from(value: &usize) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<Cow<'a, str>> for ValueRef<'a>

Source§

fn from(value: Cow<'a, str>) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<Option<f32>> for ValueRef<'a>

Source§

fn from(value: Option<f32>) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<Option<f64>> for ValueRef<'a>

Source§

fn from(value: Option<f64>) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<Option<i16>> for ValueRef<'a>

Source§

fn from(value: Option<i16>) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<Option<i32>> for ValueRef<'a>

Source§

fn from(value: Option<i32>) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<Option<i64>> for ValueRef<'a>

Source§

fn from(value: Option<i64>) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<Option<i8>> for ValueRef<'a>

Source§

fn from(value: Option<i8>) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<Option<u16>> for ValueRef<'a>

Source§

fn from(value: Option<u16>) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<Option<u32>> for ValueRef<'a>

Source§

fn from(value: Option<u32>) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<Option<u64>> for ValueRef<'a>

Source§

fn from(value: Option<u64>) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<Option<u8>> for ValueRef<'a>

Source§

fn from(value: Option<u8>) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<Option<usize>> for ValueRef<'a>

Source§

fn from(value: Option<usize>) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl From<String> for ValueRef<'_>

Source§

fn from(value: String) -> ValueRef<'_>

Converts to this type from the input type.
Source§

impl<'a> From<ValueRef<'a>> for Value

Source§

fn from(value: ValueRef<'a>) -> Value

Converts to this type from the input type.
Source§

impl From<bool> for ValueRef<'_>

Source§

fn from(value: bool) -> ValueRef<'_>

Converts to this type from the input type.
Source§

impl<'a> From<f32> for ValueRef<'a>

Source§

fn from(value: f32) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<f64> for ValueRef<'a>

Source§

fn from(value: f64) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<i16> for ValueRef<'a>

Source§

fn from(value: i16) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<i32> for ValueRef<'a>

Source§

fn from(value: i32) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<i64> for ValueRef<'a>

Source§

fn from(value: i64) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<i8> for ValueRef<'a>

Source§

fn from(value: i8) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<u16> for ValueRef<'a>

Source§

fn from(value: u16) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<u32> for ValueRef<'a>

Source§

fn from(value: u32) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<u64> for ValueRef<'a>

Source§

fn from(value: u64) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<u8> for ValueRef<'a>

Source§

fn from(value: u8) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl<'a> From<usize> for ValueRef<'a>

Source§

fn from(value: usize) -> ValueRef<'a>

Converts to this type from the input type.
Source§

impl FromStr for ValueRef<'_>

Source§

type Err = ParamValueParseError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<ValueRef<'_>, <ValueRef<'_> as FromStr>::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for ValueRef<'_>

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl ParamValue for ValueRef<'_>

Source§

fn is_empty(&self) -> bool

Check if the value is empty
Source§

fn is_i64(&self) -> bool

Check if the value is an integer
Source§

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_buffer(&self) -> bool

Check if the value is an arbitrary buffer
Source§

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

Check if the value is a boolean
Source§

fn to_bool(&self) -> Result<bool, ParamValueParseError>

Get the value as a bool, if possible
Source§

fn to_f64(&self) -> Result<f64, ParamValueParseError>

Get the value as an f64, if possible
Source§

fn to_i64(&self) -> Result<i64, ParamValueParseError>

Get the value as an i64, if possible
Source§

fn to_str(&self) -> Cow<'_, str>

Get the value as a string
Source§

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,

Convert the value’s string representation to T if possible
Source§

fn as_bytes(&self) -> Cow<'_, [u8]>

Convert the value to a byte string, the bytes of the string representation.
Source§

fn as_ref(&self) -> ValueRef<'_>

Get a reference to the stored value
Source§

fn data_len(&self) -> usize

Get the size of the stored data type
Source§

fn is_numeric(&self) -> bool

Check if the value is of either numeric type.
Source§

fn to_f32(&self) -> Result<f32, ParamValueParseError>

Get the value as an f32, if possible
Source§

fn to_i32(&self) -> Result<i32, ParamValueParseError>

Get the value as an i32, if possible
Source§

fn to_u64(&self) -> Result<u64, ParamValueParseError>

Get the value as an u64, if possible
Source§

fn as_str(&self) -> Cow<'_, str>

Get the value as a string, possibly borrowed
Source§

impl PartialEq<&str> for ValueRef<'_>

Source§

fn eq(&self, other: &&str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<String> for ValueRef<'_>

Source§

fn eq(&self, other: &String) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Value> for ValueRef<'_>

Source§

fn eq(&self, other: &Value) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> PartialEq<ValueRef<'a>> for Value

Source§

fn eq(&self, other: &ValueRef<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<bool> for ValueRef<'_>

Source§

fn eq(&self, other: &bool) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<f64> for ValueRef<'_>

Source§

fn eq(&self, other: &f64) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<i64> for ValueRef<'_>

Source§

fn eq(&self, other: &i64) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<str> for ValueRef<'_>

Source§

fn eq(&self, other: &str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> PartialEq for ValueRef<'a>

Source§

fn eq(&self, other: &ValueRef<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> PartialOrd for ValueRef<'a>

Source§

fn partial_cmp(&self, other: &ValueRef<'a>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for ValueRef<'_>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.