Skip to main content

Value

Enum Value 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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

Source

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.

Source

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

Source

pub fn to_json_with(&self, settings: &Settings) -> Result<Value, Error>

Available on crate feature 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 textwithout arbitrary_precisionwith it
-0float -0.0 (serde_json parses it as -0.0)integer 0 (Core reads the text -0)
1e400not 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.

YAMLJSON
Null, Bool, Stringthe same
integer within i64/u64number
integer outside i64/u64Y3001 (INTEGER_OUT_OF_RANGE)
finite float (-0.0 included)number
.nan, .inf, -.infY3006 (INVALID_VALUE)
Sequencearray
Mapping with string keysobject (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_depthY2005 (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

Source

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.

Source

pub fn is_null(&self) -> bool

True for Null.

Source

pub fn as_null(&self) -> Option<()>

Some(()) for Null (serde_yaml shape).

Source

pub fn is_bool(&self) -> bool

True for Bool.

Source

pub fn as_bool(&self) -> Option<bool>

The boolean, if this is a Bool.

Source

pub fn is_number(&self) -> bool

True for Number.

Source

pub fn as_number(&self) -> Option<&Number>

The number, if this is a Number.

Source

pub fn is_i64(&self) -> bool

True for an integer that fits i64.

Source

pub fn as_i64(&self) -> Option<i64>

The integer as i64, if it is one and fits.

Source

pub fn is_u64(&self) -> bool

True for an integer that fits u64.

Source

pub fn as_u64(&self) -> Option<u64>

The integer as u64, if it is one and fits.

Source

pub fn is_f64(&self) -> bool

True for a float.

Source

pub fn as_f64(&self) -> Option<f64>

The number as f64 (see Number::as_f64).

Source

pub fn is_string(&self) -> bool

True for String.

Source

pub fn as_str(&self) -> Option<&str>

The string, if this is a String.

Source

pub fn is_sequence(&self) -> bool

True for Sequence.

Source

pub fn as_sequence(&self) -> Option<&Sequence>

The sequence, if this is a Sequence.

Source

pub fn as_sequence_mut(&mut self) -> Option<&mut Sequence>

The sequence, mutably, if this is a Sequence.

Source

pub fn is_mapping(&self) -> bool

True for Mapping.

Source

pub fn as_mapping(&self) -> Option<&Mapping>

The mapping, if this is a Mapping.

Source

pub fn as_mapping_mut(&mut self) -> Option<&mut Mapping>

The mapping, mutably, if this is a Mapping.

Source

pub fn is_tagged(&self) -> bool

True for Tagged.

Source

pub fn as_tagged(&self) -> Option<&TaggedValue>

The tagged value, if this is Tagged.

Source

pub fn untag_ref(&self) -> &Value

The content under any number of tags (iterative).

Source

pub fn untag_mut(&mut self) -> &mut Value

The content under any number of tags, mutably (iterative).

Source

pub fn untag(self) -> Value

Removes all tags, returning the content (iterative).

Source

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.

Source

pub fn get_mut<I: ValueIndex>(&mut self, index: I) -> Option<&mut Value>

Like Value::get, mutably.

Trait Implementations§

Source§

impl AsKey for Value

Source§

impl Clone for Value

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Value

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Value

Source§

fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

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

The error type that can be returned if some error occurs during deserialization.
Source§

fn deserialize_any<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Require the Deserializer to figure out how to drive the visitor based on what data type is in the input. Read more
Source§

fn deserialize_bool<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a bool value.
Source§

fn deserialize_i8<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting an i8 value.
Source§

fn deserialize_i16<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting an i16 value.
Source§

fn deserialize_i32<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting an i32 value.
Source§

fn deserialize_i64<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting an i64 value.
Source§

fn deserialize_i128<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting an i128 value. Read more
Source§

fn deserialize_u8<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a u8 value.
Source§

fn deserialize_u16<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a u16 value.
Source§

fn deserialize_u32<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a u32 value.
Source§

fn deserialize_u64<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a u64 value.
Source§

fn deserialize_u128<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting an u128 value. Read more
Source§

fn deserialize_f32<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a f32 value.
Source§

fn deserialize_f64<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a f64 value.
Source§

fn deserialize_char<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a char value.
Source§

fn deserialize_str<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a string value and does not benefit from taking ownership of buffered data owned by the Deserializer. Read more
Source§

fn deserialize_string<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a string value and would benefit from taking ownership of buffered data owned by the Deserializer. Read more
Source§

fn deserialize_bytes<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a byte array and does not benefit from taking ownership of buffered data owned by the Deserializer. Read more
Source§

fn deserialize_byte_buf<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a byte array and would benefit from taking ownership of buffered data owned by the Deserializer. Read more
Source§

fn deserialize_option<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting an optional value. Read more
Source§

fn deserialize_unit<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a unit value.
Source§

fn deserialize_seq<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a sequence of values.
Source§

fn deserialize_map<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a map of key-value pairs.
Source§

fn deserialize_identifier<V: Visitor<'de>>( self, v: V, ) -> Result<V::Value, Error>

Hint that the 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>

Hint that the Deserialize type needs to deserialize a value whose type doesn’t matter because it is ignored. Read more
Source§

fn deserialize_unit_struct<V: Visitor<'de>>( self, name: &'static str, v: V, ) -> Result<V::Value, Error>

Hint that the 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>

Hint that the 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>

Hint that the 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>

Hint that the 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>

Hint that the 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>

Hint that the Deserialize type is expecting a newtype struct with a particular name.
Source§

fn is_human_readable(&self) -> bool

Determine whether Deserialize implementations should expect to deserialize their human-readable form. Read more
Source§

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

The error type that can be returned if some error occurs during deserialization.
Source§

fn deserialize_any<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Require the Deserializer to figure out how to drive the visitor based on what data type is in the input. Read more
Source§

fn deserialize_bool<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a bool value.
Source§

fn deserialize_i8<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting an i8 value.
Source§

fn deserialize_i16<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting an i16 value.
Source§

fn deserialize_i32<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting an i32 value.
Source§

fn deserialize_i64<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting an i64 value.
Source§

fn deserialize_i128<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting an i128 value. Read more
Source§

fn deserialize_u8<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a u8 value.
Source§

fn deserialize_u16<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a u16 value.
Source§

fn deserialize_u32<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a u32 value.
Source§

fn deserialize_u64<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a u64 value.
Source§

fn deserialize_u128<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting an u128 value. Read more
Source§

fn deserialize_f32<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a f32 value.
Source§

fn deserialize_f64<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a f64 value.
Source§

fn deserialize_char<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a char value.
Source§

fn deserialize_str<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a string value and does not benefit from taking ownership of buffered data owned by the Deserializer. Read more
Source§

fn deserialize_string<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a string value and would benefit from taking ownership of buffered data owned by the Deserializer. Read more
Source§

fn deserialize_bytes<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a byte array and does not benefit from taking ownership of buffered data owned by the Deserializer. Read more
Source§

fn deserialize_byte_buf<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a byte array and would benefit from taking ownership of buffered data owned by the Deserializer. Read more
Source§

fn deserialize_option<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting an optional value. Read more
Source§

fn deserialize_unit<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a unit value.
Source§

fn deserialize_seq<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a sequence of values.
Source§

fn deserialize_map<V: Visitor<'de>>(self, v: V) -> Result<V::Value, Error>

Hint that the Deserialize type is expecting a map of key-value pairs.
Source§

fn deserialize_identifier<V: Visitor<'de>>( self, v: V, ) -> Result<V::Value, Error>

Hint that the 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>

Hint that the Deserialize type needs to deserialize a value whose type doesn’t matter because it is ignored. Read more
Source§

fn deserialize_unit_struct<V: Visitor<'de>>( self, name: &'static str, v: V, ) -> Result<V::Value, Error>

Hint that the 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>

Hint that the 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>

Hint that the 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>

Hint that the 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>

Hint that the 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>

Hint that the Deserialize type is expecting a newtype struct with a particular name.
Source§

fn is_human_readable(&self) -> bool

Determine whether Deserialize implementations should expect to deserialize their human-readable form. Read more
Source§

impl Eq for Value

Source§

impl Extend<Value> for Sequence

Source§

fn extend<I: IntoIterator<Item = Value>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: T)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl From<&str> for Value

Source§

fn from(v: &str) -> Self

Converts to this type from the input type.
Source§

impl From<Mapping> for Value

Source§

fn from(v: Mapping) -> Self

Converts to this type from the input type.
Source§

impl From<Number> for Value

Source§

fn from(v: Number) -> Self

Converts to this type from the input type.
Source§

impl From<Sequence> for Value

Source§

fn from(v: Sequence) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(v: String) -> Self

Converts to this type from the input type.
Source§

impl From<TaggedValue> for Value

Source§

fn from(v: TaggedValue) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<Value>> for Value

Source§

fn from(v: Vec<Value>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(v: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for Value

Source§

fn from(v: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(v: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for Value

Source§

fn from(v: i8) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for Value

Source§

fn from(v: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(v: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(v: i64) -> Self

Converts to this type from the input type.
Source§

impl From<i128> for Value

Source§

fn from(v: i128) -> Self

Converts to this type from the input type.
Source§

impl From<isize> for Value

Source§

fn from(v: isize) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for Value

Source§

fn from(v: u8) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for Value

Source§

fn from(v: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Value

Source§

fn from(v: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Value

Source§

fn from(v: u64) -> Self

Converts to this type from the input type.
Source§

impl From<u128> for Value

Source§

fn from(v: u128) -> Self

Converts to this type from the input type.
Source§

impl From<usize> for Value

Source§

fn from(v: usize) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<Value> for Sequence

Source§

fn from_iter<I: IntoIterator<Item = Value>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<Value> for Value

Source§

fn from_iter<I: IntoIterator<Item = Value>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl Hash for Value

Source§

fn hash<H: Hasher>(&self, state: &mut H)

One u64 structural digest, consistent with == (mapping entry order does not matter), computed iteratively.

1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
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).

Source§

type Output = Value

The returned type after indexing.
Source§

fn index(&self, index: I) -> &Value

Performs the indexing (container[index]) operation. Read more
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Value

Source§

fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<&Document> for Value

Source§

fn try_from(doc: &Document) -> Result<Value, Error>

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

impl TryFrom<&Value> for Value

Available on crate feature 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§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Value) -> Result<Self, Error>

Performs the conversion.
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.

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§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(json: Value) -> Result<Self, Error>

Performs the conversion.
Source§

impl TryFrom<Value> for Value

Available on crate feature 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]");
Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Value) -> Result<Self, Error>

Performs the conversion.
Source§

impl ValueIndex 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 UnsafeUnpin for Value

§

impl UnwindSafe for Value

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.