Skip to main content

Crate gc_value

Crate gc_value 

Source
Expand description

GcValue (for Garbage-collected Value) is a generic value type, capturing the data model of common formats such as JSON, YAML, CBOR, and the INFRA API.

It uses Arc for cheap shallow cloning, mimicking the assumptions of garbage-collected language (such as Javascript).

It also supports serialization/deserialization via serde.

§Construction

GcValue provides a constructor for each variant (e.g. GcValue::new_text, GcValue::new_int, etc.), which accept any type directly convertible (with From) to the underlying data. For composite variants (like GcValue::Array or GcValue::Map), it also provides “collecting” constructors (e.g. GcValue::collect_array) that accepts any iterable of convertible types.

GcValue also implements From and FromIterator for a number of types.

§Comparison

This type implements usual comparison traits such as Eq, Ord and Hash. It should be noted that:

  • the implementation of Ord is mostly for internal use, (sorting key-value pairs in the GcValue::Map variant).
  • the implementation of Eq and Hash for the GcValue::Float variant use bit-wise comparison, not IEE754-compliant comparison. In particular, two GcValue::Float with value NaN are considered equal.

GcValue also implements PartialEq with common types, in the expected way:

Note that, for regularity, a [u8] will match a GcValue::Array, not a GcValue::Bytes.

§Tagged value

GcValue has the notion of tagged value, because this notion exists in both CBOR (with integers as tags) and YAML (with strings as tags). Note however that this notions does not have any direct correspondence in serde, and is currently not supported by the implementation of serde:Serializer. (consistently with serde_cbor, for example).

Structs§

Map
Internal representation of GcValue::Map, representing an order map where keys and values are GcValue.

Enums§

GcValue
See crate documentation.