[−][src]Enum phreak_facts::Value
Wrapper for values of different types
Variants
Integer(i64)
Uuid(Uuid)
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]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
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]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for Value
[src]
fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<Value> for Value
[src]
impl PartialOrd<Value> for Value
[src]
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool
1.0.0[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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,