pub enum Value {
Show 18 variants Null, Remove, Marker, Bool(Bool), Na, Number(Number), Str(Str), Uri(Uri), Ref(Ref), Symbol(Symbol), Date(Date), Time(Time), DateTime(DateTime), Coord(Coord), XStr(XStr), List(List), Dict(Dict), Grid(Grid),
}
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

Implements the utility functions for creating and getting the current type

source

pub fn is_null(&self) -> bool

True if this Value is a haystack Null

source

pub fn has_value(&self) -> bool

True if this Haystack Value is not null

source

pub fn make_remove() -> Value

Construct a Remove Value

source

pub fn is_remove(&self) -> bool

True if this Value is a haystack Remove

source

pub fn make_marker() -> Value

Construct a Marker Value

source

pub fn is_marker(&self) -> bool

True if this Value is a haystack Marker

source

pub fn make_bool(value: bool) -> Value

Construct a Bool Value

source

pub fn make_true() -> Value

Construct a Bool ‘true’ Value

source

pub fn is_true(&self) -> bool

True if Value is a true (Bool)crate::val::Bool

source

pub fn is_false(&self) -> bool

True if Value is a false (Bool)crate::val::Bool

source

pub fn make_false() -> Value

Construct a Bool ‘false’ Value

source

pub fn is_bool(&self) -> bool

source

pub fn make_na() -> Value

Construct a Na Value

source

pub fn is_na(&self) -> bool

True if this Value is a haystack Na

source

pub fn make_number(value: f64) -> Value

Construct a Number Value from a floating point value

source

pub fn make_int(value: i64) -> Value

Construct a Number Value from a integer value

source

pub fn make_number_unit(value: f64, unit: &'static Unit) -> Value

Construct a Number Value with an unit

source

pub fn is_number(&self) -> bool

True if this Value is a haystack Number

source

pub fn make_str(value: &str) -> Value

Construct a Str Value from a string

source

pub fn is_str(&self) -> bool

True if this Value is a haystack Str

source

pub fn make_ref(value: &str) -> Value

Construct a Ref Value from a string

source

pub fn make_ref_gen() -> Value

Construct a Ref Value by generating an unique Ref

source

pub fn make_ref_with_dis(value: &str, dis: &str) -> Value

Construct a Ref Value from a string with a display name

source

pub fn is_ref(&self) -> bool

True if this Value is a haystack Ref

source

pub fn make_symbol(value: &str) -> Value

Construct a Symbol Value from a string

source

pub fn is_symbol(&self) -> bool

True if this Value is a haystack Symbol

source

pub fn make_uri(value: &str) -> Value

Construct a Uri Value from a string

source

pub fn is_uri(&self) -> bool

True if this Value is a haystack Uri

source

pub fn make_date(value: Date) -> Value

Construct a Date Value from a Date

source

pub fn is_date(&self) -> bool

True if this Value is a haystack Date

source

pub fn make_time(value: Time) -> Value

Construct a Time Value from a Time

source

pub fn is_time(&self) -> bool

True if this Value is a haystack Time

source

pub fn make_datetime(value: DateTime) -> Value

Construct a DateTime Value from a DateTime

source

pub fn make_datetime_from_iso(value: &str) -> Result<Value, String>

Try to construct a DateTime Value from a string

source

pub fn is_datetime(&self) -> bool

True if this Value is a haystack DateTime

source

pub fn make_coord(value: Coord) -> Value

Construct a Coord Value from a Coord

source

pub fn make_coord_from(lat: f64, long: f64) -> Value

Construct a Coord Value from a latitude and longitude

source

pub fn is_coord(&self) -> bool

True if this Value is a haystack Coord

source

pub fn make_xstr(value: XStr) -> Value

Construct a XStr Value from a XStr

source

pub fn make_xstr_from(typ: &str, value: &str) -> Value

Construct a XStr Value from a type and value

source

pub fn is_xstr(&self) -> bool

True if this Value is a haystack XStr

source

pub fn make_list(value: List) -> Value

Construct a List Value from a List

source

pub fn is_list(&self) -> bool

True if this Value is a haystack List

source

pub fn make_dict(value: Dict) -> Value

Construct a Dict Value from a Dict

source

pub fn is_dict(&self) -> bool

True if this Value is a haystack Dict

source

pub fn make_grid(value: Grid) -> Value

Construct a Grid Value from a Grid

source

pub fn make_grid_from_dicts(value: Vec<Dict>) -> Value

Construct a Grid Value from a list of Dicts

source

pub fn is_grid(&self) -> bool

True if this Value is a haystack `Dict

Trait Implementations§

source§

impl Clone for Value

source§

fn clone(&self) -> Value

Returns a copy of the value. Read more
1.0.0 · 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 Default for Value

source§

fn default() -> Value

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for Value

Hayson deserializer

source§

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

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for Value

Implement user friendly display for a Value

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<&Value> for HaystackKind

source§

fn from(value: &Value) -> Self

Converts to this type from the input type.
source§

impl From<&str> for Value

Converts from &str slice to a Str Value

source§

fn from(value: &str) -> Self

Converts to this type from the input type.
source§

impl From<BTreeMap<String, Value>> for Value

Converts from DictType to a Dict Value

source§

fn from(from: DictType) -> Self

Converts to this type from the input type.
source§

impl From<Bool> for Value

Converts from Bool to a Bool Value

source§

fn from(value: Bool) -> Self

Converts to this type from the input type.
source§

impl From<Coord> for Value

Converts from Coord to a Coord Value

source§

fn from(value: Coord) -> Self

Converts to this type from the input type.
source§

impl From<Date> for Value

Converts from Date to a Date Value

source§

fn from(value: Date) -> Self

Converts to this type from the input type.
source§

impl From<DateTime<Utc>> for Value

Converts from DateTimeImpl<Utc> to a DateTime Value

source§

fn from(from: DateTimeImpl<Utc>) -> Self

Converts to this type from the input type.
source§

impl From<DateTime> for Value

Converts from DateTime to a DateTime Value

source§

fn from(value: DateTime) -> Self

Converts to this type from the input type.
source§

impl From<Dict> for Value

Converts from Dict to a Dict Value

source§

fn from(value: Dict) -> Self

Converts to this type from the input type.
source§

impl From<Grid> for Value

Converts from Grid to a Grid Value

source§

fn from(value: Grid) -> Self

Converts to this type from the input type.
source§

impl From<Marker> for Value

Converts from Marker to a Marker Value

source§

fn from(_: Marker) -> Self

Converts to this type from the input type.
source§

impl From<Na> for Value

Converts from Na to a Na Value

source§

fn from(_: Na) -> Self

Converts to this type from the input type.
source§

impl From<Number> for Value

Converts from Number to a Number Value

source§

fn from(value: Number) -> Self

Converts to this type from the input type.
source§

impl From<Ref> for Value

Converts from Ref to a Ref Value

source§

fn from(value: Ref) -> Self

Converts to this type from the input type.
source§

impl From<Remove> for Value

Converts from Remove to a Remove Value

source§

fn from(_: Remove) -> Self

Converts to this type from the input type.
source§

impl From<Str> for Value

Converts from Str to a Str Value

source§

fn from(value: Str) -> Self

Converts to this type from the input type.
source§

impl From<Symbol> for Value

Converts from Symbol to a Symbol Value

source§

fn from(value: Symbol) -> Self

Converts to this type from the input type.
source§

impl From<Time> for Value

Converts from Time to a Time Value

source§

fn from(value: Time) -> Self

Converts to this type from the input type.
source§

impl From<Uri> for Value

Converts from Uri to a Uri Value

source§

fn from(value: Uri) -> Self

Converts to this type from the input type.
source§

impl From<Vec<Value>> for Value

Converts from List to a List Value

source§

fn from(value: List) -> Self

Converts to this type from the input type.
source§

impl From<XStr> for Value

Converts from XStr to a XStr Value

source§

fn from(value: XStr) -> Self

Converts to this type from the input type.
source§

impl From<bool> for Value

Converts from bool to a Bool Value

source§

fn from(value: bool) -> Self

Converts to this type from the input type.
source§

impl From<f64> for Value

Converts from f64 to a Number Value

source§

fn from(value: f64) -> Self

Converts to this type from the input type.
source§

impl From<i32> for Value

Converts from i32 to a Number Value

source§

fn from(value: i32) -> Self

Converts to this type from the input type.
source§

impl Hash for Value

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for Value

source§

fn cmp(&self, other: &Value) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Value

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
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 · source§

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 · source§

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
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for Value

Serializes a haystack value to Haystack JSON (Hayson)

source§

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

Serialize this value into the given Serde serializer. Read more
source§

impl ToZinc for Value

Implement the Zinc encoding for Haystack Value type

source§

fn to_zinc<W: Write>(&self, writer: &mut W) -> Result<()>

source§

fn to_zinc_string(&self) -> Result<String>

Encodes this Haystack type as a Zinc string Read more
source§

impl TryFrom<&Value> for Bool

Tries to convert from Bool Value to a Bool

§

type Error = &'static str

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

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for Coord

Tries to convert from Value to a Coord

§

type Error = &'static str

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

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for Date

Tries to convert from Value to a Date

§

type Error = &'static str

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

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for DateTime

Tries to convert from Value to a DateTime

§

type Error = &'static str

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

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for Dict

Tries to convert from Value to a Dict

§

type Error = &'static str

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

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for Grid

Tries to convert from Value to a Grid

§

type Error = &'static str

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

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for Marker

Tries to convert from Marker Value to a Marker

§

type Error = &'static str

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

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for Na

Tries to convert from Na Value to a Na

§

type Error = &'static str

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

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for Number

Tries to convert from Number Value to a Number

§

type Error = &'static str

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

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for Ref

Tries to convert from Value to a Ref

§

type Error = &'static str

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

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for Remove

Tries to convert from Remove Value to a Remove

§

type Error = &'static str

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

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for Str

Tries to convert from Str Value to a Str

§

type Error = &'static str

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

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for String

Tries to convert from Str Value to a String

§

type Error = &'static str

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

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for Symbol

Tries to convert from Value to a Symbol

§

type Error = &'static str

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

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for Time

Tries to convert from Value to a Time

§

type Error = &'static str

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

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for Uri

Tries to convert from Value to a Uri

§

type Error = &'static str

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

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for List

Tries to convert from Value to a List

§

type Error = &'static str

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

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for XStr

Tries to convert from Value to a XStr

§

type Error = &'static str

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

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for bool

Tries to convert from Bool Value to a bool

§

type Error = &'static str

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

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<&Value> for f64

Tries to convert from Number Value to a f64

§

type Error = &'static str

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

fn try_from(value: &Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Eq 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§

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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
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,

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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.
source§

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