pub enum Value {
}Expand description
The Value object is the universal type that can have any of supported
tag values specified by the Project Haystack 4.0 spec.
It is implemented as an Algebraic type (enum) than can be constructed
from build-in types, such as bool or i32, and dedicated Haystack types such as Str
Usage
Creating a scalar Haystack number value
use libhaystack::val::*;
use libhaystack::units::get_unit_or_default;
let num = Value::make_number_unit(42.0, get_unit_or_default("°F"));
assert!(num.is_number());
assert_eq!(Number::try_from(&num).unwrap().unit, Some(get_unit_or_default("°F")));Creating complex structures such as a Dict
use libhaystack::dict;
use libhaystack::val::*;
let dict = Value::make_dict(dict!("strTagName" => Value::from("Str Tag value"),
"marker" => Value::make_marker()));
assert!(dict.is_dict());Creating a Haystack Grid
use libhaystack::dict;
use libhaystack::val::*;
let grid = Value::make_grid_from_dicts(vec![
dict!("dis" => Value::from("First dict row"),
"id" => Value::make_ref_gen()),
dict!("dis" => Value::from("Second dict row"),
"id" => Value::make_ref_gen())
]);
assert!(grid.is_grid());
assert_eq!(Grid::try_from(&grid).unwrap().len(), 2);Variants
Null
No value
Remove
A remove tag
Marker
Marker tag
Bool(Bool)
Bool true/false
Na
Na tag
Number(Number)
Number floating point value and optional unit
Str(Str)
Uri(Uri)
URI with string value
Ref(Ref)
Ref with string value
Symbol(Symbol)
A symbol with string value
Date(Date)
Date year, month, date
Time(Time)
Time hour, minutes, seconds with optional millis
DateTime(DateTime)
DateTime date, time and timezone
Coord(Coord)
Coordinate latitude and longitude
XStr(XStr)
XStr with type and value
List(List)
List of tags
Dict(Dict)
Dictionary of String key and Value values
Grid(Grid)
Haystack Grid
Implementations
sourceimpl Value
impl Value
Implements the utility functions for creating and getting the current type
sourcepub fn make_remove() -> Value
pub fn make_remove() -> Value
Construct a Remove Value
sourcepub fn make_marker() -> Value
pub fn make_marker() -> Value
Construct a Marker Value
sourcepub fn is_true(&self) -> bool
pub fn is_true(&self) -> bool
True if Value is a true (Bool)crate::val::Bool
sourcepub fn is_false(&self) -> bool
pub fn is_false(&self) -> bool
True if Value is a false (Bool)crate::val::Bool
sourcepub fn make_false() -> Value
pub fn make_false() -> Value
Construct a Bool ‘false’ Value
pub fn is_bool(&self) -> bool
sourcepub fn make_number(value: f64) -> Value
pub fn make_number(value: f64) -> Value
Construct a Number Value from a floating point value
sourcepub fn make_number_unit(value: f64, unit: &'static Unit) -> Value
pub fn make_number_unit(value: f64, unit: &'static Unit) -> Value
Construct a Number Value with an unit
sourcepub fn make_ref_gen() -> Value
pub fn make_ref_gen() -> Value
Construct a Ref Value by generating an unique Ref
sourcepub fn make_ref_with_dis(value: &str, dis: &str) -> Value
pub fn make_ref_with_dis(value: &str, dis: &str) -> Value
Construct a Ref Value from a string with a display name
sourcepub fn make_symbol(value: &str) -> Value
pub fn make_symbol(value: &str) -> Value
Construct a Symbol Value from a string
sourcepub fn make_datetime(value: DateTime) -> Value
pub fn make_datetime(value: DateTime) -> Value
Construct a DateTime Value from a DateTime
sourcepub fn make_datetime_from_iso(value: &str) -> Result<Value, String>
pub fn make_datetime_from_iso(value: &str) -> Result<Value, String>
Try to construct a DateTime Value from a string
sourcepub fn is_datetime(&self) -> bool
pub fn is_datetime(&self) -> bool
True if this Value is a haystack DateTime
sourcepub fn make_coord(value: Coord) -> Value
pub fn make_coord(value: Coord) -> Value
Construct a Coord Value from a Coord
sourcepub fn make_coord_from(lat: f64, long: f64) -> Value
pub fn make_coord_from(lat: f64, long: f64) -> Value
Construct a Coord Value from a latitude and longitude
sourcepub fn make_xstr_from(typ: &str, value: &str) -> Value
pub fn make_xstr_from(typ: &str, value: &str) -> Value
Construct a XStr Value from a type and value
sourcepub fn make_grid_from_dicts(value: Vec<Dict>) -> Value
pub fn make_grid_from_dicts(value: Vec<Dict>) -> Value
Construct a Grid Value from a list of Dicts
Trait Implementations
sourceimpl<'de> Deserialize<'de> for HVal
impl<'de> Deserialize<'de> for HVal
Hayson deserializer
sourcefn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<HVal, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<HVal, D::Error>
Deserialize this value from the given Serde deserializer. Read more
sourceimpl From<&'_ Value> for HaystackKind
impl From<&'_ Value> for HaystackKind
sourceimpl From<DateTime<Utc>> for Value
impl From<DateTime<Utc>> for Value
Converts from DateTimeImpl<Utc> to a DateTime Value
sourcefn from(from: DateTimeImpl<Utc>) -> Self
fn from(from: DateTimeImpl<Utc>) -> Self
Performs the conversion.
sourceimpl Ord for Value
impl Ord for Value
sourceimpl PartialOrd<Value> for Value
impl PartialOrd<Value> for Value
sourcefn partial_cmp(&self, other: &Value) -> Option<Ordering>
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 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
impl Eq for Value
impl StructuralEq for Value
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more