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§
source§impl 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 Dict
s
Trait Implementations§
source§impl<'de> Deserialize<'de> for Value
impl<'de> Deserialize<'de> for Value
Hayson deserializer
source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<HVal, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<HVal, D::Error>
source§impl From<&Value> for HaystackKind
impl From<&Value> for HaystackKind
source§impl From<DateTime<Utc>> for Value
impl From<DateTime<Utc>> for Value
Converts from DateTimeImpl<Utc>
to a DateTime
Value
source§fn from(from: DateTimeImpl<Utc>) -> Self
fn from(from: DateTimeImpl<Utc>) -> Self
source§impl Ord for Value
impl Ord for Value
source§impl PartialEq for Value
impl PartialEq for Value
source§impl PartialOrd for Value
impl PartialOrd for Value
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more