#[non_exhaustive]pub enum Value {
Null,
Bool(bool),
Number(Number),
String(String),
Sequence(Sequence),
Mapping(Mapping),
Tagged(Box<TaggedValue>),
}Expand description
An owned YAML value.
Produced only from resolved core data: the same resolver decides
the meaning of every scalar for Value, serde, and Document.
Deserialize builds the value iteratively when used with oneyaml’s
deserializers, and oneyaml’s serializers emit it iteratively (any depth
is safe; Limits::max_depth bounds it). Through other
serializers, Serialize refuses values deeper than the default
Limits::max_typed_depth (Y2007).
§Examples
The serde_yaml-style accessors:
use oneyaml::Value;
let mut v: Value = oneyaml::from_str(
"name: web\nreplicas: 3\nratio: 0.5\ndebug: false\nhost: ~\nports: [80, 443]\ncolor: !rgb ff0000\n",
)
.unwrap();
assert_eq!(v.depth(), 2);
assert!(v.is_mapping() && !v.is_sequence());
assert!(v["name"].is_string());
assert!(v["replicas"].is_number() && v["replicas"].is_i64() && v["replicas"].is_u64());
assert_eq!(v["replicas"].as_i64(), Some(3));
assert_eq!(v["replicas"].as_number().and_then(|n| n.as_u64()), Some(3));
assert!(v["ratio"].is_f64());
assert_eq!(v["ratio"].as_f64(), Some(0.5));
assert!(v["debug"].is_bool());
assert_eq!(v["debug"].as_bool(), Some(false));
assert!(v["host"].is_null());
assert_eq!(v["host"].as_null(), Some(()));
assert!(v["ports"].is_sequence());
// A tag the schema does not resolve stays on the value.
assert!(v["color"].is_tagged());
assert_eq!(v["color"].untag_ref().as_str(), Some("ff0000"));
let mut color = v["color"].clone();
*color.untag_mut() = Value::from("00ff00"); // keeps the tag
assert!(color.is_tagged());
assert_eq!(color.untag(), Value::from("00ff00"));
// Mutable access to the collections.
v.as_mapping_mut().unwrap().insert("tier".into(), "frontend".into());
v.get_mut("ports").and_then(|p| p.as_sequence_mut()).unwrap().push(8080.into());
assert_eq!(v["ports"][2].as_u64(), Some(8080));
assert_eq!(v["tier"].as_str(), Some("frontend"));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Null
null, ~, an empty node, … (per the active schema).
Bool(bool)
A boolean.
Number(Number)
An integer or float.
String(String)
A string.
Sequence(Sequence)
A sequence.
Mapping(Mapping)
A mapping with any-Value keys, in insertion order.
Tagged(Box<TaggedValue>)
A value with a tag the schema does not resolve (e.g. !color red).
Implementations§
Source§impl Value
impl Value
Sourcepub fn to_yaml_string(&self) -> Result<String, Error>
pub fn to_yaml_string(&self) -> Result<String, Error>
Writes this value as a YAML document with the default settings,
straight from the reference: no clone, iterative at any depth,
bounded by Limits::max_depth. The same output as
to_string, which, being generic over Serialize, clones a
Value once to hand it to the emitter.
let v: oneyaml::Value = oneyaml::from_str("a: [1, 'yes']").unwrap();
assert_eq!(v.to_yaml_string().unwrap(), "a:\n - 1\n - 'yes'\n");§Errors
As to_string: Y2005 past Limits::max_depth, Y3015 for a
value YAML cannot represent so that it reads back.
Sourcepub fn to_yaml_string_with(&self, settings: &Settings) -> Result<String, Error>
pub fn to_yaml_string_with(&self, settings: &Settings) -> Result<String, Error>
Value::to_yaml_string with explicit settings.
let v = oneyaml::Value::from(vec![oneyaml::Value::from(1), oneyaml::Value::from(2)]);
let s = oneyaml::Settings::new().indent(4);
assert_eq!(v.to_yaml_string_with(&s).unwrap(), "- 1\n- 2\n");§Errors
As to_string_with.
Source§impl Value
impl Value
Sourcepub fn to_json_with(&self, settings: &Settings) -> Result<Value, Error>
Available on crate feature serde_json only.
pub fn to_json_with(&self, settings: &Settings) -> Result<Value, Error>
serde_json only.This value as a serde_json::Value (feature serde_json), with
explicit Settings (only Limits::max_depth applies). What has no
JSON form is an error, never a silent coercion.
§Lossiness
JSON → YAML (TryFrom<serde_json::Value>): every JSON value has
one YAML meaning. JSON numbers are read by the one resolver as YAML
1.2 Core numbers (every JSON number is a Core !!int or !!float),
so integers of any width (serde_json’s arbitrary_precision) stay
exact; objects keep serde_json’s iteration order (sorted by key, or
insertion order with serde_json’s preserve_order feature). What
YAML receives is what serde_json holds, and serde_json’s features
change that for two inputs:
| JSON text | without arbitrary_precision | with it |
|---|---|---|
-0 | float -0.0 (serde_json parses it as -0.0) | integer 0 (Core reads the text -0) |
1e400 | not held (serde_json rejects it) | refused, Y3006 (never .inf) |
YAML → JSON is fallible (TryFrom<&Value>, to_json_with):
what has no JSON form is an error with the path of the offending node,
never a silent coercion.
| YAML | JSON |
|---|---|
Null, Bool, String | the same |
integer within i64/u64 | number |
integer outside i64/u64 | Y3001 (INTEGER_OUT_OF_RANGE) |
finite float (-0.0 included) | number |
.nan, .inf, -.inf | Y3006 (INVALID_VALUE) |
Sequence | array |
Mapping with string keys | object (see ordering above) |
a non-string key (1: x, ? [a], null: x) | Y3000 (TYPE_MISMATCH) |
Tagged (!color red) | Y3000 (TYPE_MISMATCH) |
nesting deeper than Limits::max_depth | Y2005 (VALUE_DEPTH_EXCEEDED) |
| nesting deeper than 128 levels (fixed) | Y2008 (JSON_DEPTH_EXCEEDED) |
Duplicate keys cannot arise: a Mapping has none, and only string keys
convert. YAML → JSON refuses integers beyond 64 bits even with
serde_json’s arbitrary_precision, so that direction never depends
on another crate’s feature choice.
serde_json::to_value(&value) (serde’s generic path, as with
serde_yaml) remains available and is lossy by design: it writes a tag
as a one-entry object {"!tag": content}, stringifies scalar keys, and
writes non-finite floats as null.
Both directions are iterative. A serde_json::Value drops
recursively (serde_json’s own Drop), so the one built here is at
most 128 levels deep, even under Limits::unlimited() (the
same bound as serde_json’s parser and Serialize for Value).
use oneyaml::{Limits, Settings};
let v: oneyaml::Value = oneyaml::from_str("a: {b: [1.5, true, null]}").unwrap();
let json = v.to_json_with(&Settings::new()).unwrap();
assert_eq!(json, serde_json::json!({"a": {"b": [1.5, true, null]}}));
let shallow = Settings::new().limits(Limits::default().max_depth(2));
let e = v.to_json_with(&shallow).unwrap_err();
assert_eq!(e.code(), oneyaml::code::VALUE_DEPTH_EXCEEDED);
let wide: oneyaml::Value = oneyaml::from_str("n: 18446744073709551616").unwrap();
let e = wide.to_json_with(&Settings::new()).unwrap_err();
assert_eq!(e.code(), oneyaml::code::INTEGER_OUT_OF_RANGE);
assert_eq!(e.path().unwrap().to_string(), "n");§Errors
Y3001 for an integer outside i64/u64, Y3006 for a
non-finite float, Y3000 for a non-string mapping key or a tagged
value, each with the path of the offending node (a Value has no
spans); Y2005 when the value nests deeper than max_depth;
Y2008 deeper than 128 levels.
Source§impl Value
impl Value
Sourcepub fn depth(&self) -> usize
pub fn depth(&self) -> usize
The collection nesting depth: 0 for a scalar, 1 for a collection of scalars, and so on. Tags add nothing. Iterative.
Sourcepub fn as_f64(&self) -> Option<f64>
pub fn as_f64(&self) -> Option<f64>
The number as f64 (see Number::as_f64).
Sourcepub fn is_sequence(&self) -> bool
pub fn is_sequence(&self) -> bool
True for Sequence.
Sourcepub fn as_sequence(&self) -> Option<&Sequence>
pub fn as_sequence(&self) -> Option<&Sequence>
The sequence, if this is a Sequence.
Sourcepub fn as_sequence_mut(&mut self) -> Option<&mut Sequence>
pub fn as_sequence_mut(&mut self) -> Option<&mut Sequence>
The sequence, mutably, if this is a Sequence.
Sourcepub fn is_mapping(&self) -> bool
pub fn is_mapping(&self) -> bool
True for Mapping.
Sourcepub fn as_mapping(&self) -> Option<&Mapping>
pub fn as_mapping(&self) -> Option<&Mapping>
The mapping, if this is a Mapping.
Sourcepub fn as_mapping_mut(&mut self) -> Option<&mut Mapping>
pub fn as_mapping_mut(&mut self) -> Option<&mut Mapping>
The mapping, mutably, if this is a Mapping.
Sourcepub fn as_tagged(&self) -> Option<&TaggedValue>
pub fn as_tagged(&self) -> Option<&TaggedValue>
The tagged value, if this is Tagged.
Sourcepub fn untag_mut(&mut self) -> &mut Value
pub fn untag_mut(&mut self) -> &mut Value
The content under any number of tags, mutably (iterative).
Sourcepub fn get<I: ValueIndex>(&self, index: I) -> Option<&Value>
pub fn get<I: ValueIndex>(&self, index: I) -> Option<&Value>
Looks up index (a usize for sequences, a string or Value key
for mappings), looking through tags. Never panics.
Sourcepub fn get_mut<I: ValueIndex>(&mut self, index: I) -> Option<&mut Value>
pub fn get_mut<I: ValueIndex>(&mut self, index: I) -> Option<&mut Value>
Like Value::get, mutably.
Trait Implementations§
impl AsKey for Value
Source§impl<'de> Deserialize<'de> for Value
impl<'de> Deserialize<'de> for Value
Source§fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
Source§impl<'de> Deserializer<'de> for Value
Reads an owned Value as any T: Deserialize, like
from_value (default Limits).
impl<'de> Deserializer<'de> for Value
Reads an owned Value as any T: Deserialize, like
from_value (default Limits).
use serde::Deserialize;
let v: oneyaml::Value = oneyaml::from_str("[1, 2]").unwrap();
let pair = <(u8, u8)>::deserialize(v).unwrap();
assert_eq!(pair, (1, 2));Source§type Error = Error
type Error = Error
Source§fn deserialize_any<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_any<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserializer to figure out how to drive the visitor based
on what data type is in the input. Read moreSource§fn deserialize_bool<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_bool<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting a bool value.Source§fn deserialize_i8<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_i8<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting an i8 value.Source§fn deserialize_i16<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_i16<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting an i16 value.Source§fn deserialize_i32<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_i32<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting an i32 value.Source§fn deserialize_i64<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_i64<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting an i64 value.Source§fn deserialize_u8<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_u8<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting a u8 value.Source§fn deserialize_u16<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_u16<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting a u16 value.Source§fn deserialize_u32<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_u32<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting a u32 value.Source§fn deserialize_u64<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_u64<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting a u64 value.Source§fn deserialize_f32<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_f32<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting a f32 value.Source§fn deserialize_f64<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_f64<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting a f64 value.Source§fn deserialize_char<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_char<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting a char value.Source§fn deserialize_str<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_str<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
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: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_string<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
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: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_bytes<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
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: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_byte_buf<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
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: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_option<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting an optional value. Read moreSource§fn deserialize_unit<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_unit<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting a unit value.Source§fn deserialize_seq<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_seq<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting a sequence of values.Source§fn deserialize_map<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_map<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting a map of key-value pairs.Source§fn deserialize_identifier<V: Visitor<'de>>(
self,
v: V,
) -> Result<V::Value, Error>
fn deserialize_identifier<V: Visitor<'de>>( self, v: V, ) -> Result<V::Value, Error>
Deserialize type is expecting the name of a struct
field or the discriminant of an enum variant.Source§fn deserialize_ignored_any<V: Visitor<'de>>(
self,
v: V,
) -> Result<V::Value, Error>
fn deserialize_ignored_any<V: Visitor<'de>>( self, v: V, ) -> Result<V::Value, Error>
Deserialize type needs to deserialize a value whose type
doesn’t matter because it is ignored. Read moreSource§fn deserialize_unit_struct<V: Visitor<'de>>(
self,
name: &'static str,
v: V,
) -> Result<V::Value, Error>
fn deserialize_unit_struct<V: Visitor<'de>>( self, name: &'static str, v: V, ) -> Result<V::Value, Error>
Deserialize type is expecting a unit struct with a
particular name.Source§fn deserialize_tuple<V: Visitor<'de>>(
self,
len: usize,
v: V,
) -> Result<V::Value, Error>
fn deserialize_tuple<V: Visitor<'de>>( self, len: usize, v: V, ) -> Result<V::Value, Error>
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: Visitor<'de>>(
self,
name: &'static str,
len: usize,
v: V,
) -> Result<V::Value, Error>
fn deserialize_tuple_struct<V: Visitor<'de>>( self, name: &'static str, len: usize, v: V, ) -> Result<V::Value, Error>
Deserialize type is expecting a tuple struct with a
particular name and number of fields.Source§fn deserialize_struct<V: Visitor<'de>>(
self,
name: &'static str,
fields: &'static [&'static str],
v: V,
) -> Result<V::Value, Error>
fn deserialize_struct<V: Visitor<'de>>( self, name: &'static str, fields: &'static [&'static str], v: V, ) -> Result<V::Value, Error>
Deserialize type is expecting a struct with a particular
name and fields.Source§fn deserialize_enum<V: Visitor<'de>>(
self,
name: &'static str,
variants: &'static [&'static str],
v: V,
) -> Result<V::Value, Error>
fn deserialize_enum<V: Visitor<'de>>( self, name: &'static str, variants: &'static [&'static str], v: V, ) -> Result<V::Value, Error>
Deserialize type is expecting an enum value with a
particular name and possible variants.Source§fn deserialize_newtype_struct<V: Visitor<'de>>(
self,
name: &'static str,
v: V,
) -> Result<V::Value, Error>
fn deserialize_newtype_struct<V: Visitor<'de>>( self, name: &'static str, v: V, ) -> Result<V::Value, Error>
Deserialize type is expecting a newtype struct with a
particular name.Source§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 &'de Value
Reads a borrowed Value as any T: Deserialize<'de>; string fields
may borrow from it (&str). Default Limits.
impl<'de> Deserializer<'de> for &'de Value
Reads a borrowed Value as any T: Deserialize<'de>; string fields
may borrow from it (&str). Default Limits.
use serde::Deserialize;
#[derive(Deserialize)]
struct Env<'a> {
name: &'a str,
}
let v: oneyaml::Value = oneyaml::from_str("name: LOG_LEVEL").unwrap();
let env = Env::deserialize(&v).unwrap();
assert_eq!(env.name, "LOG_LEVEL");Source§type Error = Error
type Error = Error
Source§fn deserialize_any<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_any<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserializer to figure out how to drive the visitor based
on what data type is in the input. Read moreSource§fn deserialize_bool<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_bool<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting a bool value.Source§fn deserialize_i8<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_i8<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting an i8 value.Source§fn deserialize_i16<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_i16<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting an i16 value.Source§fn deserialize_i32<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_i32<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting an i32 value.Source§fn deserialize_i64<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_i64<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting an i64 value.Source§fn deserialize_u8<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_u8<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting a u8 value.Source§fn deserialize_u16<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_u16<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting a u16 value.Source§fn deserialize_u32<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_u32<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting a u32 value.Source§fn deserialize_u64<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_u64<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting a u64 value.Source§fn deserialize_f32<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_f32<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting a f32 value.Source§fn deserialize_f64<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_f64<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting a f64 value.Source§fn deserialize_char<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_char<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting a char value.Source§fn deserialize_str<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_str<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
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: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_string<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
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: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_bytes<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
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: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_byte_buf<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
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: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_option<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting an optional value. Read moreSource§fn deserialize_unit<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_unit<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting a unit value.Source§fn deserialize_seq<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_seq<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting a sequence of values.Source§fn deserialize_map<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
fn deserialize_map<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>
Deserialize type is expecting a map of key-value pairs.Source§fn deserialize_identifier<V: Visitor<'de>>(
self,
v: V,
) -> Result<V::Value, Error>
fn deserialize_identifier<V: Visitor<'de>>( self, v: V, ) -> Result<V::Value, Error>
Deserialize type is expecting the name of a struct
field or the discriminant of an enum variant.Source§fn deserialize_ignored_any<V: Visitor<'de>>(
self,
v: V,
) -> Result<V::Value, Error>
fn deserialize_ignored_any<V: Visitor<'de>>( self, v: V, ) -> Result<V::Value, Error>
Deserialize type needs to deserialize a value whose type
doesn’t matter because it is ignored. Read moreSource§fn deserialize_unit_struct<V: Visitor<'de>>(
self,
name: &'static str,
v: V,
) -> Result<V::Value, Error>
fn deserialize_unit_struct<V: Visitor<'de>>( self, name: &'static str, v: V, ) -> Result<V::Value, Error>
Deserialize type is expecting a unit struct with a
particular name.Source§fn deserialize_tuple<V: Visitor<'de>>(
self,
len: usize,
v: V,
) -> Result<V::Value, Error>
fn deserialize_tuple<V: Visitor<'de>>( self, len: usize, v: V, ) -> Result<V::Value, Error>
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: Visitor<'de>>(
self,
name: &'static str,
len: usize,
v: V,
) -> Result<V::Value, Error>
fn deserialize_tuple_struct<V: Visitor<'de>>( self, name: &'static str, len: usize, v: V, ) -> Result<V::Value, Error>
Deserialize type is expecting a tuple struct with a
particular name and number of fields.Source§fn deserialize_struct<V: Visitor<'de>>(
self,
name: &'static str,
fields: &'static [&'static str],
v: V,
) -> Result<V::Value, Error>
fn deserialize_struct<V: Visitor<'de>>( self, name: &'static str, fields: &'static [&'static str], v: V, ) -> Result<V::Value, Error>
Deserialize type is expecting a struct with a particular
name and fields.Source§fn deserialize_enum<V: Visitor<'de>>(
self,
name: &'static str,
variants: &'static [&'static str],
v: V,
) -> Result<V::Value, Error>
fn deserialize_enum<V: Visitor<'de>>( self, name: &'static str, variants: &'static [&'static str], v: V, ) -> Result<V::Value, Error>
Deserialize type is expecting an enum value with a
particular name and possible variants.Source§fn deserialize_newtype_struct<V: Visitor<'de>>(
self,
name: &'static str,
v: V,
) -> Result<V::Value, Error>
fn deserialize_newtype_struct<V: Visitor<'de>>( self, name: &'static str, v: V, ) -> Result<V::Value, Error>
Deserialize type is expecting a newtype struct with a
particular name.Source§fn is_human_readable(&self) -> bool
fn is_human_readable(&self) -> bool
Deserialize implementations should expect to
deserialize their human-readable form. Read moreimpl Eq for Value
Source§impl Extend<Value> for Sequence
impl Extend<Value> for Sequence
Source§fn extend<I: IntoIterator<Item = Value>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = Value>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: T)
fn extend_one(&mut self, item: T)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl From<TaggedValue> for Value
impl From<TaggedValue> for Value
Source§fn from(v: TaggedValue) -> Self
fn from(v: TaggedValue) -> Self
Source§impl FromIterator<Value> for Sequence
impl FromIterator<Value> for Sequence
Source§impl FromIterator<Value> for Value
impl FromIterator<Value> for Value
Source§impl Hash for Value
impl Hash for Value
Source§impl<I: ValueIndex> Index<I> for Value
Read-only indexing that never panics: a missing index, a wrong
index type, or a non-collection yields &Value::Null. Use
Value::get to tell “missing” from “present and null”. There is
deliberately no IndexMut (no implicit auto-creation).
impl<I: ValueIndex> Index<I> for Value
Read-only indexing that never panics: a missing index, a wrong
index type, or a non-collection yields &Value::Null. Use
Value::get to tell “missing” from “present and null”. There is
deliberately no IndexMut (no implicit auto-creation).
Source§impl TryFrom<&Value> for Value
Available on crate feature serde_json only.YAML → JSON with default Limits; see Value::to_json_with.
impl TryFrom<&Value> for Value
serde_json only.YAML → JSON with default Limits; see Value::to_json_with.
let v: oneyaml::Value = oneyaml::from_str("name: web\nports: [80, 443]\n").unwrap();
let json = serde_json::Value::try_from(&v).unwrap();
assert_eq!(json, serde_json::json!({"name": "web", "ports": [80, 443]}));
let tagged: oneyaml::Value = oneyaml::from_str("color: !rgb 0f0\n").unwrap();
let e = serde_json::Value::try_from(&tagged).unwrap_err();
assert_eq!(e.code(), oneyaml::code::TYPE_MISMATCH);
assert_eq!(e.to_string(), "tagged value `!rgb` has no JSON form at color");Source§impl TryFrom<Value> for Value
Available on crate feature serde_json only.JSON → YAML (see the lossiness rules on Value::to_json_with). JSON
numbers are read as YAML 1.2 Core numbers by the one resolver, exact
at any width; objects keep serde_json’s iteration order. Iterative: any
depth is safe.
impl TryFrom<Value> for Value
serde_json only.JSON → YAML (see the lossiness rules on Value::to_json_with). JSON
numbers are read as YAML 1.2 Core numbers by the one resolver, exact
at any width; objects keep serde_json’s iteration order. Iterative: any
depth is safe.
It fails only for a number whose text overflows a float (1e400),
which only serde_json’s arbitrary_precision can hold: refused
(Y3006, with its path) rather than read as .inf.
let json = serde_json::json!({"name": "web", "replicas": 3, "ports": [80, 443]});
let yaml = oneyaml::Value::try_from(json).unwrap();
assert_eq!(oneyaml::to_string(&yaml).unwrap(), "name: web\nports:\n - 80\n - 443\nreplicas: 3\n");Source§impl TryFrom<Value> for Value
Available on crate feature serde_json only.YAML → JSON with default Limits; see Value::to_json_with.
impl TryFrom<Value> for Value
serde_json only.YAML → JSON with default Limits; see Value::to_json_with.
let v: oneyaml::Value = oneyaml::from_str("[1, .nan]").unwrap();
let e = serde_json::Value::try_from(v).unwrap_err();
assert_eq!(e.code(), oneyaml::code::INVALID_VALUE);
assert_eq!(e.path().unwrap().to_string(), "[1]");