Skip to main content

Value

Enum Value 

Source
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

Source

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.

Source

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.

Source

pub fn is_empty(&self) -> bool

Source

pub fn is_i64(&self) -> bool

Source

pub fn is_f64(&self) -> bool

Source

pub fn is_buffer(&self) -> bool

Source

pub fn is_str(&self) -> bool

Source

pub fn is_list(&self) -> bool

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 Value::Empty

Source

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

Store the value as a byte buffer

Source

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

Store the value as a boolean

Source

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

Store the value as a list

Source

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.

Source

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

Source

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

Source

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

Source

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

Source

pub fn to_buffer(&self) -> Result<Cow<'_, [u8]>, ParamValueParseError>

Source

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

Source

pub fn as_slice(&self) -> &[Self]

View this Value as a slice

Trait Implementations§

Source§

impl AsRef<Value> for Param

Source§

fn as_ref(&self) -> &Value

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

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Value

Source§

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

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

impl Default for Value

Source§

fn default() -> Value

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

impl Display for Value

Source§

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

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

impl Eq for Value

Source§

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

Source§

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

Converts to this type from the input type.
Source§

impl From<&f32> for Value

Source§

fn from(value: &f32) -> Self

Converts to this type from the input type.
Source§

impl From<&f64> for Value

Source§

fn from(value: &f64) -> Self

Converts to this type from the input type.
Source§

impl From<&i8> for Value

Source§

fn from(value: &i8) -> Self

Converts to this type from the input type.
Source§

impl From<&i16> for Value

Source§

fn from(value: &i16) -> Self

Converts to this type from the input type.
Source§

impl From<&i32> for Value

Source§

fn from(value: &i32) -> Self

Converts to this type from the input type.
Source§

impl From<&i64> for Value

Source§

fn from(value: &i64) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for Value

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl From<&u8> for Value

Source§

fn from(value: &u8) -> Self

Converts to this type from the input type.
Source§

impl From<&u16> for Value

Source§

fn from(value: &u16) -> Self

Converts to this type from the input type.
Source§

impl From<&u32> for Value

Source§

fn from(value: &u32) -> Self

Converts to this type from the input type.
Source§

impl From<&u64> for Value

Source§

fn from(value: &u64) -> Self

Converts to this type from the input type.
Source§

impl From<&usize> for Value

Source§

fn from(value: &usize) -> Self

Converts to this type from the input type.
Source§

impl From<Box<[Value]>> for Value

Source§

fn from(value: Box<[Value]>) -> Self

Converts to this type from the input type.
Source§

impl From<Cow<'_, str>> for Value

Source§

fn from(value: Cow<'_, str>) -> Self

Converts to this type from the input type.
Source§

impl From<Option<f32>> for Value

Source§

fn from(value: Option<f32>) -> Self

Converts to this type from the input type.
Source§

impl From<Option<f64>> for Value

Source§

fn from(value: Option<f64>) -> Self

Converts to this type from the input type.
Source§

impl From<Option<i8>> for Value

Source§

fn from(value: Option<i8>) -> Self

Converts to this type from the input type.
Source§

impl From<Option<i16>> for Value

Source§

fn from(value: Option<i16>) -> Self

Converts to this type from the input type.
Source§

impl From<Option<i32>> for Value

Source§

fn from(value: Option<i32>) -> Self

Converts to this type from the input type.
Source§

impl From<Option<i64>> for Value

Source§

fn from(value: Option<i64>) -> Self

Converts to this type from the input type.
Source§

impl From<Option<u8>> for Value

Source§

fn from(value: Option<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<Option<u16>> for Value

Source§

fn from(value: Option<u16>) -> Self

Converts to this type from the input type.
Source§

impl From<Option<u32>> for Value

Source§

fn from(value: Option<u32>) -> Self

Converts to this type from the input type.
Source§

impl From<Option<u64>> for Value

Source§

fn from(value: Option<u64>) -> Self

Converts to this type from the input type.
Source§

impl From<Option<usize>> for Value

Source§

fn from(value: Option<usize>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

impl From<Vec<Value>> for Value

Source§

fn from(value: Vec<Value>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(value: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for Value

Source§

fn from(value: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for Value

Source§

fn from(value: i8) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for Value

Source§

fn from(value: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(value: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for Value

Source§

fn from(value: u8) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for Value

Source§

fn from(value: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Value

Source§

fn from(value: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Value

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

impl From<usize> for Value

Source§

fn from(value: usize) -> Self

Converts to this type from the input type.
Source§

impl<U: Into<Value>> FromIterator<U> for Value

Source§

fn from_iter<T: IntoIterator<Item = U>>(iter: T) -> Self

Creates a value from an iterator. Read more
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.

Source§

type Err = ParamValueParseError

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

fn from_str(s: &str) -> Result<Self, Self::Err>

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

impl Hash for Value

Source§

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

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 Value

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 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: FromStr>(&self) -> Result<T, T::Err>

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

Check if the value is a list
Source§

fn as_slice(&self) -> Cow<'_, [Value]>

Get the value as a slice
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 for Value

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<&str> for Value

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<String> for Value

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<Value> for ValueRef<'_>

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

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

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<bool> for Value

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<f64> for Value

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<i64> for Value

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<str> for Value

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for Value

Source§

fn partial_cmp(&self, other: &Value) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 StructuralPartialEq for Value

Auto Trait Implementations§

§

impl Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnsafeUnpin for Value

§

impl UnwindSafe for Value

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