Skip to main content

AsKey

Trait AsKey 

Source
pub trait AsKey: Sealed { }
Expand description

A mapping key for Document::get, NodeRef::get, NodeMut::get_mut, NodeMut::insert and the other key lookups and inserts of the edit API.

Implemented for str, String, the integer types, bool, and Value (and references to each). Sealed: the set of key types is part of the API’s meaning.

What a key matches is what Value equality says: a string key matches the keys that resolve to that string (get("1") does not match the integer key 1, get(1) does); any other key matches the scalar keys whose resolved value equals it (~, null and an empty key are one key, 0x10 and 16 are one key).

An error naming a key (EditError::at) gives a non-string key as its Core text: the integer key 3 and the string key "3" both appear as path!["3"] (Path keys are text).

use oneyaml::{Document, Value};

let doc = Document::parse("1: one\n'1': quoted\ntrue: yes\n~: nothing\n").unwrap();
assert_eq!(doc.get(1).unwrap().text(), "one");
assert_eq!(doc.get("1").unwrap().text(), "quoted");
assert_eq!(doc.get(String::from("1")).unwrap().text(), "quoted");
assert_eq!(doc.get(true).unwrap().text(), "yes");
assert_eq!(doc.get(&Value::Null).unwrap().text(), "nothing");

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl AsKey for String

Source§

impl AsKey for bool

Source§

impl AsKey for i8

Source§

impl AsKey for i16

Source§

impl AsKey for i32

Source§

impl AsKey for i64

Source§

impl AsKey for i128

Source§

impl AsKey for isize

Source§

impl AsKey for str

Source§

impl AsKey for u8

Source§

impl AsKey for u16

Source§

impl AsKey for u32

Source§

impl AsKey for u64

Source§

impl AsKey for u128

Source§

impl AsKey for usize

Source§

impl<T: AsKey + ?Sized> AsKey for &T

Implementors§