Enum serde_yaml::value::Value
source · pub enum Value {
Null,
Bool(bool),
Number(Number),
String(String),
Sequence(Sequence),
Mapping(Mapping),
Tagged(Box<TaggedValue>),
}
Expand description
Represents any valid YAML value.
Variants§
Null
Represents a YAML null value.
Bool(bool)
Represents a YAML boolean.
Number(Number)
Represents a YAML numerical value, whether integer or floating point.
String(String)
Represents a YAML string.
Sequence(Sequence)
Represents a YAML sequence in which the elements are
serde_yaml::Value
.
Mapping(Mapping)
Represents a YAML mapping in which the keys and values are both
serde_yaml::Value
.
Tagged(Box<TaggedValue>)
A representation of YAML’s !Tag
syntax, used for enums.
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 a YAML sequence 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 sequence.
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 a sequence 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 sequence.
use serde_yaml::Value;
let object: Value = serde_yaml::from_str(r#"{ A: 65, B: 66, C: 67 }"#)?;
let x = object.get("A").unwrap();
assert_eq!(x, 65);
let sequence: Value = serde_yaml::from_str(r#"[ "A", "B", "C" ]"#)?;
let x = sequence.get(2).unwrap();
assert_eq!(x, &Value::String("C".into()));
assert_eq!(sequence.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 object: Value = serde_yaml::from_str(r#"
A: [a, á, à]
B: [b, b́]
C: [c, ć, ć̣, ḉ]
42: true
"#)?;
assert_eq!(object["B"][0], Value::String("b".into()));
assert_eq!(object[Value::String("D".into())], Value::Null);
assert_eq!(object["D"], Value::Null);
assert_eq!(object[0]["x"]["y"]["z"], Value::Null);
assert_eq!(object[42], Value::Bool(true));
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>
Index into a YAML sequence 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 sequence.
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 a sequence 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 sequence.
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 = serde_yaml::from_str("null").unwrap();
assert!(v.is_null());
let v: Value = serde_yaml::from_str("false").unwrap();
assert!(!v.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 = serde_yaml::from_str("null").unwrap();
assert_eq!(v.as_null(), Some(()));
let v: Value = serde_yaml::from_str("false").unwrap();
assert_eq!(v.as_null(), None);
sourcepub fn is_bool(&self) -> bool
pub fn is_bool(&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 = serde_yaml::from_str("true").unwrap();
assert!(v.is_bool());
let v: Value = serde_yaml::from_str("42").unwrap();
assert!(!v.is_bool());
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 = serde_yaml::from_str("true").unwrap();
assert_eq!(v.as_bool(), Some(true));
let v: Value = serde_yaml::from_str("42").unwrap();
assert_eq!(v.as_bool(), None);
sourcepub fn is_number(&self) -> bool
pub fn is_number(&self) -> bool
Returns true if the Value
is a Number. Returns false otherwise.
let v: Value = serde_yaml::from_str("5").unwrap();
assert!(v.is_number());
let v: Value = serde_yaml::from_str("true").unwrap();
assert!(!v.is_number());
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 v: Value = serde_yaml::from_str("1337").unwrap();
assert!(v.is_i64());
let v: Value = serde_yaml::from_str("null").unwrap();
assert!(!v.is_i64());
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 v: Value = serde_yaml::from_str("1337").unwrap();
assert_eq!(v.as_i64(), Some(1337));
let v: Value = serde_yaml::from_str("false").unwrap();
assert_eq!(v.as_i64(), None);
sourcepub fn is_u64(&self) -> bool
pub fn is_u64(&self) -> bool
Returns true if the Value
is an integer between u64::MIN
and
u64::MAX
.
For any Value on which is_u64
returns true, as_u64
is guaranteed to
return the integer value.
let v: Value = serde_yaml::from_str("1337").unwrap();
assert!(v.is_u64());
let v: Value = serde_yaml::from_str("null").unwrap();
assert!(!v.is_u64());
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 = serde_yaml::from_str("1337").unwrap();
assert_eq!(v.as_u64(), Some(1337));
let v: Value = serde_yaml::from_str("false").unwrap();
assert_eq!(v.as_u64(), None);
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.
Currently this function returns true if and only if both is_i64
and
is_u64
return false but this is not a guarantee in the future.
let v: Value = serde_yaml::from_str("256.01").unwrap();
assert!(v.is_f64());
let v: Value = serde_yaml::from_str("true").unwrap();
assert!(!v.is_f64());
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 = serde_yaml::from_str("13.37").unwrap();
assert_eq!(v.as_f64(), Some(13.37));
let v: Value = serde_yaml::from_str("false").unwrap();
assert_eq!(v.as_f64(), None);
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 = serde_yaml::from_str("'lorem ipsum'").unwrap();
assert!(v.is_string());
let v: Value = serde_yaml::from_str("42").unwrap();
assert!(!v.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 = serde_yaml::from_str("'lorem ipsum'").unwrap();
assert_eq!(v.as_str(), Some("lorem ipsum"));
let v: Value = serde_yaml::from_str("false").unwrap();
assert_eq!(v.as_str(), None);
sourcepub fn is_sequence(&self) -> bool
pub fn is_sequence(&self) -> bool
Returns true if the Value
is a sequence. Returns false otherwise.
let v: Value = serde_yaml::from_str("[1, 2, 3]").unwrap();
assert!(v.is_sequence());
let v: Value = serde_yaml::from_str("true").unwrap();
assert!(!v.is_sequence());
sourcepub fn as_sequence(&self) -> Option<&Sequence>
pub fn as_sequence(&self) -> Option<&Sequence>
If the Value
is a sequence, return a reference to it if possible.
Returns None otherwise.
let v: Value = serde_yaml::from_str("[1, 2]").unwrap();
assert_eq!(v.as_sequence(), Some(&vec![Value::Number(Number::from(1)), Value::Number(Number::from(2))]));
let v: Value = serde_yaml::from_str("false").unwrap();
assert_eq!(v.as_sequence(), None);
sourcepub fn as_sequence_mut(&mut self) -> Option<&mut Sequence>
pub fn as_sequence_mut(&mut self) -> Option<&mut Sequence>
If the Value
is a sequence, return a mutable reference to it if
possible. Returns None otherwise.
let mut v: Value = serde_yaml::from_str("[1]").unwrap();
let s = v.as_sequence_mut().unwrap();
s.push(Value::Number(Number::from(2)));
assert_eq!(s, &vec![Value::Number(Number::from(1)), Value::Number(Number::from(2))]);
let mut v: Value = serde_yaml::from_str("false").unwrap();
assert_eq!(v.as_sequence_mut(), None);
sourcepub fn is_mapping(&self) -> bool
pub fn is_mapping(&self) -> bool
Returns true if the Value
is a mapping. Returns false otherwise.
let v: Value = serde_yaml::from_str("a: 42").unwrap();
assert!(v.is_mapping());
let v: Value = serde_yaml::from_str("true").unwrap();
assert!(!v.is_mapping());
sourcepub fn as_mapping(&self) -> Option<&Mapping>
pub fn as_mapping(&self) -> Option<&Mapping>
If the Value
is a mapping, return a reference to it if possible.
Returns None otherwise.
let v: Value = serde_yaml::from_str("a: 42").unwrap();
let mut expected = Mapping::new();
expected.insert(Value::String("a".into()),Value::Number(Number::from(42)));
assert_eq!(v.as_mapping(), Some(&expected));
let v: Value = serde_yaml::from_str("false").unwrap();
assert_eq!(v.as_mapping(), None);
sourcepub fn as_mapping_mut(&mut self) -> Option<&mut Mapping>
pub fn as_mapping_mut(&mut self) -> Option<&mut Mapping>
If the Value
is a mapping, return a reference to it if possible.
Returns None otherwise.
let mut v: Value = serde_yaml::from_str("a: 42").unwrap();
let m = v.as_mapping_mut().unwrap();
m.insert(Value::String("b".into()), Value::Number(Number::from(21)));
let mut expected = Mapping::new();
expected.insert(Value::String("a".into()), Value::Number(Number::from(42)));
expected.insert(Value::String("b".into()), Value::Number(Number::from(21)));
assert_eq!(m, &expected);
let mut v: Value = serde_yaml::from_str("false").unwrap();
assert_eq!(v.as_mapping_mut(), None);
sourcepub fn apply_merge(&mut self) -> Result<(), Error>
pub fn apply_merge(&mut self) -> Result<(), Error>
Performs merging of <<
keys into the surrounding mapping.
The intended use of this in YAML is described in https://yaml.org/type/merge.html.
use serde_yaml::Value;
let config = "\
tasks:
build: &webpack_shared
command: webpack
args: build
inputs:
- 'src/**/*'
start:
<<: *webpack_shared
args: start
";
let mut value: Value = serde_yaml::from_str(config).unwrap();
value.apply_merge().unwrap();
assert_eq!(value["tasks"]["start"]["command"], "webpack");
assert_eq!(value["tasks"]["start"]["args"], "start");
Trait Implementations§
source§impl Default for Value
impl Default for Value
The default value is Value::Null
.
This is useful for handling omitted Value
fields when deserializing.
§Examples
use serde::Deserialize;
use serde_yaml::Value;
#[derive(Deserialize)]
struct Settings {
level: i32,
#[serde(default)]
extras: Value,
}
let data = r#" { "level": 42 } "#;
let s: Settings = serde_yaml::from_str(data)?;
assert_eq!(s.level, 42);
assert_eq!(s.extras, Value::Null);
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, Error>where
V: Visitor<'de>,
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, 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_bool<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize
type is expecting a bool
value.source§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_char<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize
type is expecting a char
value.source§fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, 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, Error>where
V: Visitor<'de>,
fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, 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, Error>where
V: Visitor<'de>,
fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, 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, Error>where
V: Visitor<'de>,
fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, 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_option<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize
type is expecting an optional value. Read moresource§fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, 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, Error>where
V: Visitor<'de>,
fn deserialize_unit_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize
type is expecting a unit struct with a
particular name.source§fn deserialize_newtype_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_newtype_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize
type is expecting a newtype struct with a
particular name.source§fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, 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, Error>where
V: Visitor<'de>,
fn deserialize_tuple<V>(
self,
_len: usize,
visitor: V,
) -> Result<V::Value, 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, Error>where
V: Visitor<'de>,
fn deserialize_tuple_struct<V>(
self,
_name: &'static str,
_len: usize,
visitor: V,
) -> Result<V::Value, 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, Error>where
V: Visitor<'de>,
fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, 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, Error>where
V: Visitor<'de>,
fn deserialize_struct<V>(
self,
_name: &'static str,
_fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize
type is expecting a struct with a particular
name and fields.source§fn deserialize_enum<V>(
self,
_name: &str,
_variants: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_enum<V>(
self,
_name: &str,
_variants: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize
type is expecting an enum value with a
particular name and possible variants.source§fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, 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, Error>where
V: Visitor<'de>,
fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, 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, Error>where
V: Visitor<'de>,
fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, 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_bool<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_bool<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize
type is expecting a bool
value.source§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_char<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize
type is expecting a char
value.source§fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, 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, Error>where
V: Visitor<'de>,
fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, 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, Error>where
V: Visitor<'de>,
fn deserialize_bytes<V>(self, visitor: V) -> Result<V::Value, 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, Error>where
V: Visitor<'de>,
fn deserialize_byte_buf<V>(self, visitor: V) -> Result<V::Value, 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_option<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize
type is expecting an optional value. Read moresource§fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_unit<V>(self, visitor: V) -> Result<V::Value, 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, Error>where
V: Visitor<'de>,
fn deserialize_unit_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize
type is expecting a unit struct with a
particular name.source§fn deserialize_newtype_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_newtype_struct<V>(
self,
_name: &'static str,
visitor: V,
) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize
type is expecting a newtype struct with a
particular name.source§fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_seq<V>(self, visitor: V) -> Result<V::Value, 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, Error>where
V: Visitor<'de>,
fn deserialize_tuple<V>(
self,
_len: usize,
visitor: V,
) -> Result<V::Value, 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, Error>where
V: Visitor<'de>,
fn deserialize_tuple_struct<V>(
self,
_name: &'static str,
_len: usize,
visitor: V,
) -> Result<V::Value, 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, Error>where
V: Visitor<'de>,
fn deserialize_map<V>(self, visitor: V) -> Result<V::Value, 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, Error>where
V: Visitor<'de>,
fn deserialize_struct<V>(
self,
_name: &'static str,
_fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize
type is expecting a struct with a particular
name and fields.source§fn deserialize_enum<V>(
self,
_name: &str,
_variants: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_enum<V>(
self,
_name: &str,
_variants: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Error>where
V: Visitor<'de>,
Deserialize
type is expecting an enum value with a
particular name and possible variants.source§fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, 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, Error>where
V: Visitor<'de>,
fn deserialize_ignored_any<V>(self, visitor: V) -> Result<V::Value, 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(f: Cow<'a, str>) -> Self
fn from(f: Cow<'a, str>) -> Self
Convert copy-on-write string to Value
§Examples
use serde_yaml::Value;
use std::borrow::Cow;
let s: Cow<str> = Cow::Borrowed("lorem");
let x: Value = s.into();
use serde_yaml::Value;
use std::borrow::Cow;
let s: Cow<str> = Cow::Owned("lorem".to_string());
let x: Value = s.into();
source§impl<T: Into<Value>> FromIterator<T> for Value
impl<T: Into<Value>> 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
Convert an iteratable type to a YAML sequence
§Examples
use serde_yaml::Value;
let v = std::iter::repeat(42).take(5);
let x: Value = v.collect();
use serde_yaml::Value;
let v: Vec<_> = vec!["lorem", "ipsum", "dolor"];
let x: Value = v.into_iter().collect();
use std::iter::FromIterator;
use serde_yaml::Value;
let x: Value = Value::from_iter(vec!["lorem", "ipsum", "dolor"]);
source§impl<I> Index<I> for Valuewhere
I: Index,
impl<I> Index<I> for Valuewhere
I: Index,
source§fn index(&self, index: I) -> &Value
fn index(&self, index: I) -> &Value
Index into a serde_yaml::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 a sequence
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 sequence.
For retrieving deeply nested values, you should have a look at the
Value::pointer
method.
§Examples
let data: serde_yaml::Value = serde_yaml::from_str(r#"{ x: { y: [z, zz] } }"#)?;
assert_eq!(data["x"]["y"], serde_yaml::from_str::<Value>(r#"["z", "zz"]"#).unwrap());
assert_eq!(data["x"]["y"][0], serde_yaml::from_str::<Value>(r#""z""#).unwrap());
assert_eq!(data["a"], serde_yaml::from_str::<Value>(r#"null"#).unwrap()); // returns null for undefined values
assert_eq!(data["a"]["b"], serde_yaml::from_str::<Value>(r#"null"#).unwrap()); // does not panic
source§impl<I> IndexMut<I> for Valuewhere
I: Index,
impl<I> IndexMut<I> for Valuewhere
I: Index,
source§fn index_mut(&mut self, index: I) -> &mut Value
fn index_mut(&mut self, index: I) -> &mut Value
Write into a serde_yaml::Value
using the syntax value[0] = ...
or
value["k"] = ...
.
If the index is a number, the value must be a sequence of length bigger than the index. Indexing into a value that is not a sequence or a sequence that is too small will panic.
If the index is a string, the value must be an object or null which is treated like an empty object. If the key is not already present in the object, it will be inserted with a value of null. Indexing into a value that is neither an object nor null will panic.
§Examples
let mut data: serde_yaml::Value = serde_yaml::from_str(r#"{x: 0}"#)?;
// replace an existing key
data["x"] = serde_yaml::from_str(r#"1"#)?;
// insert a new key
data["y"] = serde_yaml::from_str(r#"[false, false, false]"#)?;
// replace a value in a sequence
data["y"][0] = serde_yaml::from_str(r#"true"#)?;
// inserted a deeply nested key
data["a"]["b"]["c"]["d"] = serde_yaml::from_str(r#"true"#)?;
println!("{:?}", data);
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 PartialEq<String> for Value
impl PartialEq<String> for Value
source§impl PartialOrd for Value
impl PartialOrd for Value
source§impl<'de> VariantAccess<'de> for &'de Value
impl<'de> VariantAccess<'de> for &'de Value
source§type Error = Error
type Error = Error
EnumAccess
.source§fn unit_variant(self) -> Result<(), Error>
fn unit_variant(self) -> Result<(), Error>
source§fn newtype_variant_seed<T>(self, seed: T) -> Result<T::Value, Error>where
T: DeserializeSeed<'de>,
fn newtype_variant_seed<T>(self, seed: T) -> Result<T::Value, Error>where
T: DeserializeSeed<'de>,
source§fn tuple_variant<V>(self, _len: usize, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn tuple_variant<V>(self, _len: usize, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
source§fn struct_variant<V>(
self,
_fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn struct_variant<V>(
self,
_fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Error>where
V: Visitor<'de>,
source§fn newtype_variant<T>(self) -> Result<T, Self::Error>where
T: Deserialize<'de>,
fn newtype_variant<T>(self) -> Result<T, Self::Error>where
T: Deserialize<'de>,
source§impl<'de> VariantAccess<'de> for Value
impl<'de> VariantAccess<'de> for Value
source§type Error = Error
type Error = Error
EnumAccess
.source§fn unit_variant(self) -> Result<(), Error>
fn unit_variant(self) -> Result<(), Error>
source§fn newtype_variant_seed<T>(self, seed: T) -> Result<T::Value, Error>where
T: DeserializeSeed<'de>,
fn newtype_variant_seed<T>(self, seed: T) -> Result<T::Value, Error>where
T: DeserializeSeed<'de>,
source§fn tuple_variant<V>(self, _len: usize, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn tuple_variant<V>(self, _len: usize, visitor: V) -> Result<V::Value, Error>where
V: Visitor<'de>,
source§fn struct_variant<V>(
self,
_fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Error>where
V: Visitor<'de>,
fn struct_variant<V>(
self,
_fields: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Error>where
V: Visitor<'de>,
source§fn newtype_variant<T>(self) -> Result<T, Self::Error>where
T: Deserialize<'de>,
fn newtype_variant<T>(self) -> Result<T, Self::Error>where
T: Deserialize<'de>,
impl Eq for Value
impl Index for Value
impl Index for Value
impl StructuralPartialEq for Value
Auto Trait Implementations§
impl Freeze for Value
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.