pub enum Value {
Bool(bool),
Int(i64),
Uint(u64),
BigInt(Vec<u8>),
Float(f64),
Str(String),
Inst(DateTime<Utc>),
Dur(TimeDelta),
UUID([u8; 16]),
Arr(Vec<Value>),
Map(Box<HashMap<Key, Value>>),
UnitVar(String),
}Expand description
type that represent a structom value.
Values are wrappers that represent any structom value, builtin or user defined.
they can be created manually or from source or binary, manipulated or converted to native types, and stringified or serialized.
§api
Value can be created through different forms
// manually
Value::from(1) // => Uint(1)
// from source
parse("1", &ParseOptions::default(), &VoidProvider{}); // => Uint(1)
// from binary
decode(&[0, 16, 1], &VoidProvider{}); // => Uint(1)Value has different methods for manipulation its value.
let value = Value::Uint(1);
// test type
value.is_uint(); // => true
// get ref to inner value
value.as_uint(); // => Some(1)
// compare inner value
value == 1; // => true
// index for array and map
Value::from(vec![1, 2, 3])[1] // => Uint(2)Value can be transformed into other forms.
let value = Value::Uint(1);
// convert to native type
value.cast<u64>(); // => Ok(1)
// stringify the value
stringify(value, &StringifyOptions::default()); // => "1"
// encode into binary
encode(value); // => [0, 16, 1]§representation
builtin types are represented through their respective variant.
structs are represented through the Map variant where it contains the struct fields.
enums are represented by the UnitVar case it is unit variant.
else they are represented by a Map variant containing the fields, with a special key $enum_variant representing the variant name.
for metadata wrapped types, they are represented by a Map variant containing the metadata with their values, with a special keys: $has_meta of value true and value containing the wrapped value.
Variants§
Bool(bool)
boolean value, types: bool.
Int(i64)
signed integer value, types: i8, i16, i32, i64 vint.
Uint(u64)
unsigned integer value, types: u8, u16, u32, u64 vuint.
BigInt(Vec<u8>)
big integer value, types: bint.
Float(f64)
floating point value, types: f32, f64
Str(String)
string value, types: str, unit enums.
Inst(DateTime<Utc>)
instance value, types: inst, instN.
Dur(TimeDelta)
duration value, types: dur.
UUID([u8; 16])
uuid value, types: uuid.
Arr(Vec<Value>)
array value, types: arr.
Map(Box<HashMap<Key, Value>>)
map value, types: map, structs, enums with fields.
UnitVar(String)
unit variant enum, types: enum.
Implementations§
Source§impl Value
is_T() -> bool: whether the inner value is of type T.
impl Value
is_T() -> bool: whether the inner value is of type T.
pub fn is_bool(&self) -> bool
pub fn is_uint(&self) -> bool
pub fn is_int(&self) -> bool
pub fn is_str(&self) -> bool
pub fn is_bigint(&self) -> bool
pub fn is_float(&self) -> bool
pub fn is_inst(&self) -> bool
pub fn is_dur(&self) -> bool
pub fn is_uuid(&self) -> bool
pub fn is_array(&self) -> bool
pub fn is_map(&self) -> bool
pub fn is_unit_variant(&self) -> bool
Source§impl Value
impl Value
Sourcepub fn enum_variant(&self) -> Option<&str>
pub fn enum_variant(&self) -> Option<&str>
get name of the wrapped enum variant, if not enum return None.
Sourcepub fn inner(&self) -> &Value
pub fn inner(&self) -> &Value
get the inner value of a metadata wrapped type, else return self.
Sourcepub fn inner_mut(&mut self) -> &mut Value
pub fn inner_mut(&mut self) -> &mut Value
get mut ref to the inner value of a metadata wrapped type, else return self.
Sourcepub fn into_inner(self) -> Value
pub fn into_inner(self) -> Value
unwrap the inner value of a metadata wrapped type, else return self.
Source§impl Value
as_T() -> Option<T>: get copy of the inner value if it is of type T, else None.
impl Value
as_T() -> Option<T>: get copy of the inner value if it is of type T, else None.
as_ref_T() -> Option<T>: get reference to the inner value if it is of type T, else None.
as_mut_T() -> Option<T>: get mutable reference to the inner value if it is of type T, else None.
pub fn as_bool(&self) -> Option<bool>
pub fn as_int(&self) -> Option<i64>
pub fn as_uint(&self) -> Option<u64>
pub fn as_float(&self) -> Option<f64>
pub fn as_inst(&self) -> Option<DateTime<Utc>>
pub fn as_dur(&self) -> Option<TimeDelta>
pub fn as_uuid(&self) -> Option<[u8; 16]>
pub fn as_str(&self) -> Option<&str>
pub fn as_slice(&self) -> Option<&[Value]>
pub fn as_bigint(&self) -> Option<&[u8]>
pub fn as_map(&self) -> Option<&HashMap<Key, Value>>
pub fn as_vec_mut(&mut self) -> Option<&mut Vec<Value>>
pub fn as_map_mut(&mut self) -> Option<&mut HashMap<Key, Value>>
Source§impl Value
impl Value
Sourcepub fn get_by_index<I: SliceIndex<[Value]>>(
&self,
index: I,
) -> Option<&<I as SliceIndex<[Value]>>::Output>
pub fn get_by_index<I: SliceIndex<[Value]>>( &self, index: I, ) -> Option<&<I as SliceIndex<[Value]>>::Output>
get an item in value by index if it is an array, else return None.
Sourcepub fn get_by_index_mut<I: SliceIndex<[Value]>>(
&mut self,
index: I,
) -> Option<&mut <I as SliceIndex<[Value]>>::Output>
pub fn get_by_index_mut<I: SliceIndex<[Value]>>( &mut self, index: I, ) -> Option<&mut <I as SliceIndex<[Value]>>::Output>
get a mutable reference to an item in value by index if it is an array, else return None.
Sourcepub fn get_by_key(&self, key: &Key) -> Option<&Value>
pub fn get_by_key(&self, key: &Key) -> Option<&Value>
get an item in value by key if it is a map, else return None.
Sourcepub fn get_by_key_mut(&mut self, key: &Key) -> Option<&mut Value>
pub fn get_by_key_mut(&mut self, key: &Key) -> Option<&mut Value>
get a mutable reference to an item in value by key if it is a map, else return None.