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".