Skip to main content

Value

Enum Value 

Source
#[non_exhaustive]
pub enum Value { Null, Undefined, Bool(bool), Integer(i64), Float(f64), String(String), List(Vec<Value>), Map(Map), Date(Date), DateTime(DateTime), Duration(Duration), }
Expand description

A predicator value.

Null and Undefined are both values and neither is the other: undefined is an absence (no value was ever supplied), null is a value that is present and empty. An integer is an i64; a float an f64.

Equality (==) is strict: two values are equal when they are the same kind and the same value, so Integer(1) and Float(1.0) are not equal, two instants are equal when they are the same instant, and lists and maps are equal member by member. Ordering (partial_cmp) agrees with it: integers and floats order by number (an integer and a float at the same number are unordered, being unequal), strings by codepoint, false before true, dates and instants chronologically, lists member by member with a proper prefix first; two maps, two durations or two values of other kinds are unordered unless equal. The compare instruction’s own rules are the evaluator’s, not these.

Equality, ordering, cloning, Debug and dropping walk a value without recursion, so a value nested deeper than the stack is compared, copied, printed and dropped without exhausting it. Because Value implements Drop, a member is taken out of a value with core::mem::replace rather than moved out of a pattern.

use predicator_rs::Value;

let list = Value::from(vec![Value::from(1), Value::from("x"), Value::Null]);
assert_eq!(list, Value::List(vec![1.into(), "x".into(), Value::Null]));
assert_ne!(Value::from(1), Value::from(1.0));
assert!(Value::from(1) < Value::from(1.5));
assert_ne!(Value::Null, Value::Undefined);

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Null

A value that is present and empty.

§

Undefined

An absence: no value was ever supplied.

§

Bool(bool)

true or false.

§

Integer(i64)

An integer.

§

Float(f64)

A float.

§

String(String)

A string.

§

List(Vec<Value>)

A list.

§

Map(Map)

A map from Keys.

§

Date(Date)

A civil date.

§

DateTime(DateTime)

An instant in UTC.

§

Duration(Duration)

A duration.

Trait Implementations§

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<'de> Deserialize<'de> for Value

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Value, D::Error>

Reads a value in the tagged encoding.

Source§

impl Drop for Value

Source§

fn drop(&mut self)

Drops the members of a list or a map from a work list rather than by recursion: each member is emptied of its own members before it is dropped.

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl From<&str> for Value

Source§

fn from(text: &str) -> Value

Converts to this type from the input type.
Source§

impl From<Date> for Value

Source§

fn from(date: Date) -> Value

Converts to this type from the input type.
Source§

impl From<DateTime> for Value

Source§

fn from(instant: DateTime) -> Value

Converts to this type from the input type.
Source§

impl From<Duration> for Value

Source§

fn from(duration: Duration) -> Value

Converts to this type from the input type.
Source§

impl From<Map> for Value

Source§

fn from(map: Map) -> Value

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(text: String) -> Value

Converts to this type from the input type.
Source§

impl From<Vec<Value>> for Value

Source§

fn from(items: Vec<Value>) -> Value

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(flag: bool) -> Value

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(number: f64) -> Value

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(number: i64) -> Value

Converts to this type from the input type.
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 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 Serialize for Value

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Forget for Value

§

impl Freeze for Value

§

impl Move 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.