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

Implements the utility functions for creating and getting the current type

True if this Value is a haystack Null

True if this Haystack Value is not null

Construct a Remove Value

True if this Value is a haystack Remove

Construct a Marker Value

True if this Value is a haystack Marker

Construct a Bool Value

Construct a Bool ‘true’ Value

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

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

Construct a Bool ‘false’ Value

Construct a Na Value

True if this Value is a haystack Na

Construct a Number Value from a floating point value

Construct a Number Value from a integer value

Construct a Number Value with an unit

True if this Value is a haystack Number

Construct a Str Value from a string

True if this Value is a haystack Str

Construct a Ref Value from a string

Construct a Ref Value by generating an unique Ref

Construct a Ref Value from a string with a display name

True if this Value is a haystack Ref

Construct a Symbol Value from a string

True if this Value is a haystack Symbol

Construct a Uri Value from a string

True if this Value is a haystack Uri

Construct a Date Value from a Date

True if this Value is a haystack Date

Construct a Time Value from a Time

True if this Value is a haystack Time

Construct a DateTime Value from a DateTime

Try to construct a DateTime Value from a string

True if this Value is a haystack DateTime

Construct a Coord Value from a Coord

Construct a Coord Value from a latitude and longitude

True if this Value is a haystack Coord

Construct a XStr Value from a XStr

Construct a XStr Value from a type and value

True if this Value is a haystack XStr

Construct a List Value from a List

True if this Value is a haystack List

Construct a Dict Value from a Dict

True if this Value is a haystack Dict

Construct a Grid Value from a Grid

Construct a Grid Value from a list of Dicts

True if this Value is a haystack `Dict

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Implements the Default trait for the Value

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

Hayson deserializer

Deserialize this value from the given Serde deserializer. Read more

Implement user friendly display for a Value

Formats the value using the given formatter. Read more

Performs the conversion.

Converts from &str slice to a Str Value

Performs the conversion.

Converts from DictType to a Dict Value

Performs the conversion.

Converts from Bool to a Bool Value

Performs the conversion.

Converts from Coord to a Coord Value

Performs the conversion.

Converts from Date to a Date Value

Performs the conversion.

Converts from DateTimeImpl<Utc> to a DateTime Value

Performs the conversion.

Converts from DateTime to a DateTime Value

Performs the conversion.

Converts from Dict to a Dict Value

Performs the conversion.

Converts from Grid to a Grid Value

Performs the conversion.

Converts from Marker to a Marker Value

Performs the conversion.

Converts from Na to a Na Value

Performs the conversion.

Converts from Number to a Number Value

Performs the conversion.

Converts from Ref to a Ref Value

Performs the conversion.

Converts from Remove to a Remove Value

Performs the conversion.

Converts from Str to a Str Value

Performs the conversion.

Converts from Symbol to a Symbol Value

Performs the conversion.

Converts from Time to a Time Value

Performs the conversion.

Converts from Uri to a Uri Value

Performs the conversion.

Converts from List to a List Value

Performs the conversion.

Converts from XStr to a XStr Value

Performs the conversion.

Converts from bool to a Bool Value

Performs the conversion.

Converts from f64 to a Number Value

Performs the conversion.

Converts from i32 to a Number Value

Performs the conversion.

Feeds this value into the given Hasher. Read more

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

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

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

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

Serializes a haystack value to Haystack JSON (Hayson)

Serialize this value into the given Serde serializer. Read more

Implement the Zinc encoding for Haystack Value type

Encodes this Haystack type as a Zinc string Read more

Tries to convert from Bool Value to a bool

The type returned in the event of a conversion error.

Performs the conversion.

Tries to convert from Bool Value to a Bool

The type returned in the event of a conversion error.

Performs the conversion.

Tries to convert from Number Value to a f64

The type returned in the event of a conversion error.

Performs the conversion.

Tries to convert from Number Value to a Number

The type returned in the event of a conversion error.

Performs the conversion.

Tries to convert from Value to a Ref

The type returned in the event of a conversion error.

Performs the conversion.

Tries to convert from Remove Value to a Remove

The type returned in the event of a conversion error.

Performs the conversion.

Tries to convert from Str Value to a String

The type returned in the event of a conversion error.

Performs the conversion.

Tries to convert from Str Value to a Str

The type returned in the event of a conversion error.

Performs the conversion.

Tries to convert from Value to a Symbol

The type returned in the event of a conversion error.

Performs the conversion.

Tries to convert from Value to a Time

The type returned in the event of a conversion error.

Performs the conversion.

Tries to convert from Value to a Uri

The type returned in the event of a conversion error.

Performs the conversion.

Tries to convert from Value to a XStr

The type returned in the event of a conversion error.

Performs the conversion.

Tries to convert from Value to a Coord

The type returned in the event of a conversion error.

Performs the conversion.

Tries to convert from Value to a Date

The type returned in the event of a conversion error.

Performs the conversion.

Tries to convert from Value to a DateTime

The type returned in the event of a conversion error.

Performs the conversion.

Tries to convert from Value to a Dict

The type returned in the event of a conversion error.

Performs the conversion.

Tries to convert from Value to a Grid

The type returned in the event of a conversion error.

Performs the conversion.

Tries to convert from Value to a List

The type returned in the event of a conversion error.

Performs the conversion.

Tries to convert from Marker Value to a Marker

The type returned in the event of a conversion error.

Performs the conversion.

Tries to convert from Na Value to a Na

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.