#[non_exhaustive]pub enum Value {
Null,
Bool(bool),
Number(Number),
String(String),
ByteArray(Vec<u8>),
Array(Vec<Value>),
Map(Map<String, Value>),
}Expand description
A loosely typed value that can be stored in a session.
Though this data structure looks quite similar to (and is, in fact, largely
based on) serde_json::Value, there are a few key differences:
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Null
Bool(bool)
Number(Number)
String(String)
ByteArray(Vec<u8>)
Array(Vec<Value>)
Map(Map<String, Value>)
Implementations§
Source§impl Value
impl Value
Sourcepub fn get<I: Index>(&self, index: I) -> Option<&Value>
pub fn get<I: Index>(&self, index: I) -> Option<&Value>
Index into an array or map. A string index can be used to access a value
in a map, and a usize index can be used to access an element of an
array.
Returns None if the type of self does not match the type of the
index, for example if the index is a string and self is an array or a
number. Also returns None if the given key does not exist in the map
or the given index is not within the bounds of the array.
let map = Value::from_iter([("A", 65), ("B", 66), ("C", 64)]);
assert_eq!(*map.get("A").unwrap(), 65);
let array = Value::from(["A", "B", "C"]);
assert_eq!(*array.get(2).unwrap(), "C");
assert_eq!(array.get("A"), None);Square brackets can also be used to index into a value in a more concise
way. This returns Value::Null in cases where get would have returned
None.
let map = Value::from_iter([
("A", &["a", "á", "à"] as &[_]),
("B", &["b", "b́"]),
("C", &["c", "ć", "ć̣", "ḉ"]),
]);
assert_eq!(map["B"][0], "b");
assert_eq!(map["D"], Value::Null);
assert_eq!(map[0]["x"]["y"]["z"], Value::Null);Sourcepub fn get_mut<I: Index>(&mut self, index: I) -> Option<&mut Value>
pub fn get_mut<I: Index>(&mut self, index: I) -> Option<&mut Value>
Mutably index into an array or map. A string index can be used to access
a value in a map, and a usize index can be used to access an element
of an array.
Returns None if the type of self does not match the type of the
index, for example if the index is a string and self is an array or a
number. Also returns None if the given key does not exist in the map
or the given index is not within the bounds of the array.
let mut map = Value::from_iter([("A", 65), ("B", 66), ("C", 67)]);
*map.get_mut("A").unwrap() = Value::from(69);
let mut array = Value::from(["A", "B", "C"]);
*array.get_mut(2).unwrap() = Value::from("D");Sourcepub fn is_map(&self) -> bool
pub fn is_map(&self) -> bool
Returns true if the Value is a Map. Returns false otherwise.
For any Value on which is_map returns true, as_map and
as_map_mut are guaranteed to return the Map representation.
let map = Value::from_iter([
("a", Value::from_iter([("nested", true)])),
("b", Value::from(["an", "array"])),
]);
assert!(map.is_map());
assert!(map["a"].is_map());
assert!(!map["b"].is_map())Sourcepub fn as_map(&self) -> Option<&Map<String, Value>>
pub fn as_map(&self) -> Option<&Map<String, Value>>
If the Value is a Map, returns the associated Map. Returns
None otherwise.
let v = Value::from_iter([
("a", Value::from_iter([("nested", true)])),
("b", Value::from(["an", "array"])),
]);
assert_eq!(v["a"].as_map().unwrap().len(), 1);
assert_eq!(v["b"].as_map(), None);Sourcepub fn as_map_mut(&mut self) -> Option<&mut Map<String, Value>>
pub fn as_map_mut(&mut self) -> Option<&mut Map<String, Value>>
If the Value is a Map, returns the associated mutable Map.
Returns None otherwise.
let mut v = Value::from_iter([
("a", Value::from_iter([("nested", true)])),
]);
v["a"].as_map_mut().unwrap().clear();
assert_eq!(v, Value::from_iter([("a", Value::Map(Map::new()))]));Sourcepub fn is_array(&self) -> bool
pub fn is_array(&self) -> bool
Returns true if the Value is an Array. Returns false otherwise.
For any Value on which is_array returns true, as_array and
as_array_mut are guaranteed to return the vector representing the
array.
NOTE: If the Value is a ByteArray, this method will return
false.
let map = Value::from_iter([
("a", Value::from(["an", "array"])),
("b", Value::from_bytes(b"a byte array")),
("c", Value::from_iter([("a", "map")])),
]);
assert!(map["a"].is_array());
assert!(!map["b"].is_array());
assert!(!map["c"].is_array());Sourcepub fn as_array(&self) -> Option<&Vec<Value>>
pub fn as_array(&self) -> Option<&Vec<Value>>
If the Value is an Array, returns the associated vector. Returns
None otherwise.
NOTE: If the Value is a ByteArray, this method will return
None.
let v = Value::from_iter([
("a", Value::from(["an", "array"])),
("b", Value::from_bytes(b"a byte array")),
("c", Value::from_iter([("a", "map")])),
]);
assert_eq!(v["a"].as_array().unwrap().len(), 2);
assert_eq!(v["b"].as_array(), None);
assert_eq!(v["c"].as_array(), None);Sourcepub fn as_array_mut(&mut self) -> Option<&mut Vec<Value>>
pub fn as_array_mut(&mut self) -> Option<&mut Vec<Value>>
If the Value is an Array, returns the associated mutable vector.
Returns None otherwise.
NOTE: If the Value is a ByteArray, this method will return
None.
let mut v = Value::from_iter([
("a", ["an", "array"]),
]);
v["a"].as_array_mut().unwrap().clear();
assert_eq!(v, Value::from_iter([("a", &[] as &[&str])]));Sourcepub fn is_string(&self) -> bool
pub fn is_string(&self) -> bool
Returns true if the Value is a String. Returns false otherwise.
For any Value on which is_string returns true, as_str is
guaranteed to return the string slice.
let v = Value::from_iter([
("a", Value::from("some string")),
("b", Value::from_bytes(b"some bytes")),
("c", Value::from(false)),
]);
assert!(v["a"].is_string());
assert!(!v["b"].is_string());
assert!(!v["c"].is_string());Sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
If the Value is a String, returns the associated str. Returns
None otherwise.
let v = Value::from_iter([
("a", Value::from("some string")),
("b", Value::from_bytes(b"some bytes")),
("c", Value::from(false)),
]);
assert_eq!(v["a"].as_str(), Some("some string"));
assert_eq!(v["b"].as_str(), None);
assert_eq!(v["c"].as_str(), None);Sourcepub fn is_bytes(&self) -> bool
pub fn is_bytes(&self) -> bool
Returns true if the Value is a ByteArray. Returns false
otherwise.
For any Value on which is_bytes returns true, as_bytes is
guaranteed to return the byte slice.
let v = Value::from_iter([
("a", Value::from_bytes(b"some bytes")),
("b", Value::from(false)),
("c", Value::from("some string")),
]);
assert!(v["a"].is_bytes());
assert!(!v["b"].is_bytes());
assert!(!v["c"].is_bytes());Sourcepub fn as_bytes(&self) -> Option<&[u8]>
pub fn as_bytes(&self) -> Option<&[u8]>
If the Value is a ByteArray, returns the associated &[u8].
Returns None otherwise.
let v = Value::from_iter([
("a", Value::from_bytes(b"some bytes")),
("b", Value::from(false)),
("c", Value::from("some string")),
]);
assert_eq!(v["a"].as_bytes(), Some(b"some bytes".as_slice()));
assert_eq!(v["b"].as_bytes(), None);
assert_eq!(v["c"].as_bytes(), None);Sourcepub fn as_number(&self) -> Option<&Number>
pub fn as_number(&self) -> Option<&Number>
If the Value is a Number, returns the associated Number. Returns
None otherwise.
let v = Value::from_iter([
("a", Value::from(1)),
("b", Value::try_from(2.2f64).unwrap_or_default()),
("c", Value::from(-3)),
("d", Value::from("4")),
]);
assert_eq!(v["a"].as_number(), Some(&Number::from(1u64)));
assert_eq!(v["b"].as_number(), Some(&Number::from_f64(2.2).unwrap()));
assert_eq!(v["c"].as_number(), Some(&Number::from(-3i64)));
assert_eq!(v["d"].as_number(), None);Sourcepub fn is_i64(&self) -> bool
pub fn is_i64(&self) -> bool
Returns true if the Value is an integer between i64::MIN and
i64::MAX.
For any Value on which is_i64 returns true, as_i64 is
guaranteed to return the integer value.
let big = i64::max_value() as u64 + 10;
let v = Value::from_iter([
("a", Value::from(64)),
("b", Value::from(big)),
("c", Value::try_from(256.0).unwrap_or_default()),
]);
assert!(v["a"].is_i64());
// Greater than `i64::MAX`.
assert!(!v["b"].is_i64());
// Numbers with a decimal point are not considered integers.
assert!(!v["c"].is_i64());Sourcepub fn is_u64(&self) -> bool
pub fn is_u64(&self) -> bool
Returns true if the Value is an integer between 0 and
u64::MAX.
For any Value on which is_u64 returns true, as_u64 is
guaranteed to return the integer value.
let v = Value::from_iter([
("a", Value::from(64)),
("b", Value::from(-64)),
("c", Value::try_from(256.0).unwrap_or_default()),
]);
assert!(v["a"].is_u64());
// Negative integer.
assert!(!v["b"].is_u64());
// Numbers with a decimal point are not considered integers.
assert!(!v["c"].is_u64());Sourcepub fn is_f64(&self) -> bool
pub fn is_f64(&self) -> bool
Returns true if the Value is a number that can be represented by
f64.
For any Value on which is_f64 returns true, as_f64 is
guaranteed to return the floating point value.
This function returns true if and only if both is_i64 and
is_u64 return false.
let v = Value::from_iter([
("a", Value::try_from(256.0).unwrap_or_default()),
("b", Value::from(64)),
("c", Value::from(-64)),
]);
assert!(v["a"].is_f64());
// Integers.
assert!(!v["b"].is_f64());
assert!(!v["c"].is_f64());Sourcepub fn as_i64(&self) -> Option<i64>
pub fn as_i64(&self) -> Option<i64>
If the Value is an integer, represent it as i64 if possible. Returns
None otherwise.
let big = i64::max_value() as u64 + 10;
let v = Value::from_iter([
("a", Value::from(64)),
("b", Value::from(big)),
("c", Value::try_from(256.0).unwrap_or_default()),
]);
assert_eq!(v["a"].as_i64(), Some(64));
assert_eq!(v["b"].as_i64(), None);
assert_eq!(v["c"].as_i64(), None);Sourcepub fn as_u64(&self) -> Option<u64>
pub fn as_u64(&self) -> Option<u64>
If the Value is an integer, represent it as u64 if possible. Returns
None otherwise.
let v = Value::from_iter([
("a", Value::from(64)),
("b", Value::from(-64)),
("c", Value::try_from(256.0).unwrap_or_default()),
]);
assert_eq!(v["a"].as_u64(), Some(64));
assert_eq!(v["b"].as_u64(), None);
assert_eq!(v["c"].as_u64(), None);Sourcepub fn as_f64(&self) -> Option<f64>
pub fn as_f64(&self) -> Option<f64>
If the Value is a number, represent it as f64 if possible. Returns
None otherwise.
let v = Value::from_iter([
("a", Value::try_from(256.0).unwrap_or_default()),
("b", Value::from(64)),
("c", Value::from(-64)),
]);
assert_eq!(v["a"].as_f64(), Some(256.0));
assert_eq!(v["b"].as_f64(), Some(64.0));
assert_eq!(v["c"].as_f64(), Some(-64.0));Sourcepub fn is_boolean(&self) -> bool
pub fn is_boolean(&self) -> bool
Returns true if the Value is a Boolean. Returns false otherwise.
For any Value on which is_boolean returns true, as_bool is
guaranteed to return the boolean value.
let v = Value::from_iter([
("a", Value::from(false)),
("b", Value::from("false")),
]);
assert!(v["a"].is_boolean());
// The string `"false"` is a string, not a boolean.
assert!(!v["b"].is_boolean());Sourcepub fn as_bool(&self) -> Option<bool>
pub fn as_bool(&self) -> Option<bool>
If the Value is a Boolean, returns the associated bool. Returns
None otherwise.
let v = Value::from_iter([
("a", Value::from(false)),
("b", Value::from("false")),
]);
assert_eq!(v["a"].as_bool(), Some(false));
// The string `"false"` is a string, not a boolean.
assert_eq!(v["b"].as_bool(), None);Sourcepub fn is_null(&self) -> bool
pub fn is_null(&self) -> bool
Returns true if the Value is a Null. Returns false otherwise.
For any Value on which is_null returns true, as_null is
guaranteed to return Some(()).
let v = Value::from_iter([
("a", Value::Null),
("b", Value::try_from(f64::NAN).unwrap_or_default()),
("c", Value::from(false)),
]);
assert!(v["a"].is_null());
assert!(v["b"].is_null());
// The boolean `false` is not null.
assert!(!v["c"].is_null());Sourcepub fn as_null(&self) -> Option<()>
pub fn as_null(&self) -> Option<()>
If the Value is a Null, returns (). Returns None otherwise.
let v = Value::from_iter([
("a", Value::Null),
("b", Value::try_from(f64::NAN).unwrap_or_default()),
("c", Value::from(false)),
]);
assert_eq!(v["a"].as_null(), Some(()));
assert_eq!(v["b"].as_null(), Some(()));
// The boolean `false` is not null.
assert_eq!(v["c"].as_null(), None);Trait Implementations§
Source§impl<'de> Deserialize<'de> for Value
impl<'de> Deserialize<'de> for Value
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<'de> Deserializer<'de> for &'de Value
impl<'de> Deserializer<'de> for &'de Value
Source§type Error = Error
type Error = Error
Source§fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserializer to figure out how to drive the visitor based
on what data type is in the input. Read moreSource§fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize type is expecting an i8 value.Source§fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize type is expecting an i16 value.Source§fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize type is expecting an i32 value.Source§fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize type is expecting an i64 value.Source§fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize type is expecting a u8 value.Source§fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize type is expecting a u16 value.Source§fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize type is expecting a u32 value.Source§fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize type is expecting a u64 value.Source§fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize type is expecting a f32 value.Source§fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize type is expecting a f64 value.Source§fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting an optional value. Read moreSource§fn deserialize_enum<V>(
self,
name: &'static str,
variants: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_enum<V>(
self,
name: &'static str,
variants: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting an enum value with a
particular name and possible variants.Source§fn deserialize_newtype_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_newtype_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting a newtype struct with a
particular name.Source§fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting a bool value.Source§fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting a char value.Source§fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting a string value and does
not benefit from taking ownership of buffered data owned by the
Deserializer. Read moreSource§fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting a string value and would
benefit from taking ownership of buffered data owned by the
Deserializer. Read moreSource§fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting a byte array and does not
benefit from taking ownership of buffered data owned by the
Deserializer. Read moreSource§fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting a byte array and would
benefit from taking ownership of buffered data owned by the
Deserializer. Read moreSource§fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting a unit value.Source§fn deserialize_unit_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_unit_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting a unit struct with a
particular name.Source§fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting a sequence of values.Source§fn deserialize_tuple<V>(
self,
_len: usize,
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_tuple<V>(
self,
_len: usize,
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting a sequence of values and
knows how many values there are without looking at the serialized data.Source§fn deserialize_tuple_struct<V>(
self,
_name: &'static str,
_len: usize,
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_tuple_struct<V>(
self,
_name: &'static str,
_len: usize,
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting a tuple struct with a
particular name and number of fields.Source§fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting a map of key-value pairs.Source§fn deserialize_struct<V>(
self,
_name: &'static str,
_fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_struct<V>(
self,
_name: &'static str,
_fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting a struct with a particular
name and fields.Source§fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting the name of a struct
field or the discriminant of an enum variant.Source§fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type needs to deserialize a value whose type
doesn’t matter because it is ignored. Read moreSource§fn is_human_readable(&self) -> bool
fn is_human_readable(&self) -> bool
Deserialize implementations should expect to
deserialize their human-readable form. Read moreSource§impl<'de> Deserializer<'de> for Value
impl<'de> Deserializer<'de> for Value
Source§type Error = Error
type Error = Error
Source§fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserializer to figure out how to drive the visitor based
on what data type is in the input. Read moreSource§fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_i8<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize type is expecting an i8 value.Source§fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_i16<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize type is expecting an i16 value.Source§fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_i32<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize type is expecting an i32 value.Source§fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_i64<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize type is expecting an i64 value.Source§fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_u8<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize type is expecting a u8 value.Source§fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_u16<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize type is expecting a u16 value.Source§fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_u32<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize type is expecting a u32 value.Source§fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize type is expecting a u64 value.Source§fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_f32<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize type is expecting a f32 value.Source§fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize type is expecting a f64 value.Source§fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting an optional value. Read moreSource§fn deserialize_enum<V>(
self,
name: &'static str,
variants: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_enum<V>(
self,
name: &'static str,
variants: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting an enum value with a
particular name and possible variants.Source§fn deserialize_newtype_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_newtype_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting a newtype struct with a
particular name.Source§fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting a bool value.Source§fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting a char value.Source§fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting a string value and does
not benefit from taking ownership of buffered data owned by the
Deserializer. Read moreSource§fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting a string value and would
benefit from taking ownership of buffered data owned by the
Deserializer. Read moreSource§fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting a byte array and does not
benefit from taking ownership of buffered data owned by the
Deserializer. Read moreSource§fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting a byte array and would
benefit from taking ownership of buffered data owned by the
Deserializer. Read moreSource§fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting a unit value.Source§fn deserialize_unit_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_unit_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting a unit struct with a
particular name.Source§fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting a sequence of values.Source§fn deserialize_tuple<V>(
self,
_len: usize,
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_tuple<V>(
self,
_len: usize,
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting a sequence of values and
knows how many values there are without looking at the serialized data.Source§fn deserialize_tuple_struct<V>(
self,
_name: &'static str,
_len: usize,
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_tuple_struct<V>(
self,
_name: &'static str,
_len: usize,
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting a tuple struct with a
particular name and number of fields.Source§fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting a map of key-value pairs.Source§fn deserialize_struct<V>(
self,
name: &'static str,
fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_struct<V>(
self,
name: &'static str,
fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting a struct with a particular
name and fields.Source§fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type is expecting the name of a struct
field or the discriminant of an enum variant.Source§fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>where
V: Visitor<'de>,
Deserialize type needs to deserialize a value whose type
doesn’t matter because it is ignored. Read moreSource§fn is_human_readable(&self) -> bool
fn is_human_readable(&self) -> bool
Deserialize implementations should expect to
deserialize their human-readable form. Read moreSource§impl<'a> From<Cow<'a, str>> for Value
impl<'a> From<Cow<'a, str>> for Value
Source§fn from(value: Cow<'a, str>) -> Self
fn from(value: Cow<'a, str>) -> Self
Convert clone-on-write string to Value::String.
§Examples
use std::borrow::Cow;
use tower_sesh::Value;
let s: Cow<str> = Cow::Borrowed("lorem");
let x: Value = s.into();
let s: Cow<str> = Cow::Owned("lorem".to_owned());
let x: Value = s.into();Source§impl<K, V> FromIterator<(K, V)> for Value
impl<K, V> FromIterator<(K, V)> for Value
Source§fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self
Create a Value::Map by collecting an iterator of key-value pairs.
§Examples
let v: Vec<_> = vec![("lorem", 40), ("ipsum", 2)];
let x: Value = v.into_iter().collect();Source§impl<T> FromIterator<T> for Value
impl<T> FromIterator<T> for Value
Source§fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
Create a Value::Array by collecting an iterator of array elements.
§Examples
let v = std::iter::repeat(42).take(5);
let x: Value = v.collect();let v: Vec<_> = vec!["lorem", "ipsum", "dolor"];
let x: Value = v.into_iter().collect();let x: Value = Value::from_iter(vec!["lorem", "ipsum", "dolor"]);Source§impl<Idx> Index<Idx> for Valuewhere
Idx: Index,
impl<Idx> Index<Idx> for Valuewhere
Idx: Index,
Source§fn index(&self, index: Idx) -> &Self::Output
fn index(&self, index: Idx) -> &Self::Output
Index into a Value using the syntax value[0] or value["k"].
Returns Value::Null if the type of self does not match the type of
the index, for example if the index is a string and self is an array
or a number. Also returns Value::Null if the given key does not exist
in the map or the given index is not within the bounds of the array.
§Examples
let value = Value::from_iter([
("x", Value::from_iter([
("y", ["z", "zz"]),
])),
]);
assert_eq!(value["x"]["y"], Value::from(["z", "zz"]));
assert_eq!(value["x"]["y"][0], Value::from("z"));
assert_eq!(value["a"], Value::Null); // returns null for undefined values
assert_eq!(value["a"]["b"], Value::Null); // does not panicSource§impl<Idx> IndexMut<Idx> for Valuewhere
Idx: Index,
impl<Idx> IndexMut<Idx> for Valuewhere
Idx: Index,
Source§fn index_mut(&mut self, index: Idx) -> &mut Self::Output
fn index_mut(&mut self, index: Idx) -> &mut Self::Output
Write into a Value using the syntax value[0] = ... or
value["k"] = ....
If the index is a number, the value must be an array of length bigger than the index. Indexing into a value that is not an array or an array that is too small will panic.
If the index is a string, the value must be a map (or null which is treated like an empty map). If the key is not already present in the map, it will be inserted with a value of null. Indexing into a value that is neither a map nor null will panic.
§Examples
let mut value = Value::from_iter([("x", 0)]);
// replace an existing key
value["x"] = Value::from(1);
// insert a new key
value["y"] = Value::from([false, false, false]);
// replace an array value
value["y"][0] = Value::from(true);
// inserted a deeply nested key
value["a"]["b"]["c"]["d"] = Value::from(true);
println!("{:?}", value);Source§impl<'de> IntoDeserializer<'de, Error> for &'de Value
impl<'de> IntoDeserializer<'de, Error> for &'de Value
Source§type Deserializer = &'de Value
type Deserializer = &'de Value
Source§fn into_deserializer(self) -> Self::Deserializer
fn into_deserializer(self) -> Self::Deserializer
Source§impl<'de> IntoDeserializer<'de, Error> for Value
impl<'de> IntoDeserializer<'de, Error> for Value
Source§type Deserializer = Value
type Deserializer = Value
Source§fn into_deserializer(self) -> Self::Deserializer
fn into_deserializer(self) -> Self::Deserializer
Source§impl TryFrom<f32> for Value
impl TryFrom<f32> for Value
Source§fn try_from(value: f32) -> Result<Self, Self::Error>
fn try_from(value: f32) -> Result<Self, Self::Error>
Convert a 32-bit floating point number to Value::Number, or return
an error if infinite or NaN.
§Examples
let f: f32 = 13.37;
let x: Value = f.try_into().unwrap();Source§impl TryFrom<f64> for Value
impl TryFrom<f64> for Value
Source§fn try_from(value: f64) -> Result<Self, Self::Error>
fn try_from(value: f64) -> Result<Self, Self::Error>
Convert a 64-bit floating point number to Value::Number, or return
an error if infinite or NaN.
§Examples
let f: f64 = 13.37;
let x: Value = f.try_into().unwrap();