[][src]Enum phreak_facts::Value

pub enum Value {
    Integer(i64),
    Uuid(Uuid),
    DateTime(DateTime<Utc>),
    String(String),
}

Wrapper for values of different types

Variants

Integer(i64)
Uuid(Uuid)
DateTime(DateTime<Utc>)
String(String)

Implementations

impl Value[src]

pub fn new() -> Self[src]

Create a Value containing the empty string

pub fn describe(&self) -> &str[src]

Returns the type-name of the Value


assert_eq!(Value::from("text").describe(), "string");
assert_eq!(Value::from(42).describe(), "integer");

pub fn typed_cmp(&self, other: &Self) -> Option<Ordering>[src]

Compare function that doesn't convert types, but only compares compatible types, resulting in a Partial Ordening

The standard ordening of Value, as implemented by PartialOrd and Ord performs ordering based on type-order as to meet the strict requirements imposed by Hash and BTree datatypes. This is not the desired behavior for comparing in the Phreak network, so we provide a type-aware alternative.

for PartialOrd the following holds Int.cmp(Str) == Some(Ordering::Less), or Integer < String, while Int.typed_cmp(Str) == None, so no ordering between types.


// compare different numeric types
assert_eq!(Value::from(15u8).typed_cmp( &Value::from(15i32) ), Some(Ordering::Equal));
assert_eq!(Value::from(15u8).typed_cmp( &Value::from(5i32) ), Some(Ordering::Greater));
assert_eq!(Value::from(8u8).typed_cmp( &Value::from(15i32) ), Some(Ordering::Less));

let t = String::from("text");

// compare &str and String
assert_eq!(Value::from("text").typed_cmp( &Value::from(t) ), Some(Ordering::Equal));
assert_eq!(Value::from("b").typed_cmp( &Value::from("a") ), Some(Ordering::Greater));

// can't compare strings and integers
assert_eq!(Value::from("5").typed_cmp( &Value::from(5u8) ), None);
// or string and uuid
assert_eq!(Value::from("5").typed_cmp( &Value::from(Uuid::new_v4()) ), None);
// or uuid and integers
assert_eq!(Value::from(Uuid::new_v4()).typed_cmp( &Value::from(5u8) ), None);

// whereas partial_cmp and cmp succeed (strings come after integers in our storage)
assert_eq!(Value::from("5").partial_cmp( &Value::from(5u8) ), Some(Ordering::Greater));
assert_eq!(Value::from("5").cmp( &Value::from(5u8) ), Ordering::Greater);

pub fn typed_eq(&self, other: &Self) -> bool[src]

Equality function that doesn't convert types, but checks the type of the value.

The standard equality of Value, as implemented by PartialEq and Eq does type conversions in order to meet the strict requirements imposed by Hash and BTree datatypes. This is not the desired behavior for equality in the Phreak network, so we provide a type-aware alternative.


// compare different numeric types
assert_eq!(Value::from(15u8).typed_eq( &Value::from(15i32) ), true);
assert_eq!(Value::from(15u8).typed_eq( &Value::from(5i32) ), false);

// compare int and &str
assert_eq!(Value::from(8).typed_eq( &Value::from("8") ), false);

// compare &str and String
assert_eq!(Value::from("8").typed_eq( &Value::from("8".to_string()) ), true);

Trait Implementations

impl Clone for Value[src]

impl Debug for Value[src]

impl Default for Value[src]

impl<'de> Deserialize<'de> for Value[src]

impl Display for Value[src]

impl Eq for Value[src]

impl<'_> From<&'_ str> for Value[src]

impl<T: TimeZone> From<DateTime<T>> for Value[src]

impl From<String> for Value[src]

impl From<Uuid> for Value[src]

impl From<i16> for Value[src]

impl From<i32> for Value[src]

impl From<i64> for Value[src]

impl From<i8> for Value[src]

impl From<u16> for Value[src]

impl From<u32> for Value[src]

impl From<u8> for Value[src]

impl Hash for Value[src]

impl Ord for Value[src]

impl PartialEq<Value> for Value[src]

impl PartialOrd<Value> for Value[src]

impl Serialize for Value[src]

Auto Trait Implementations

impl RefUnwindSafe for Value

impl Send for Value

impl Sync for Value

impl Unpin for Value

impl UnwindSafe for Value

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,