pub struct ToonMap(/* private fields */);Expand description
An ordered map of string keys to TOON values.
This is a thin wrapper around IndexMap that maintains insertion order,
which is important for deterministic TOON serialization.
§Examples
use serde_toon::{ToonMap, Value};
let mut map = ToonMap::new();
map.insert("first".to_string(), Value::from(1));
map.insert("second".to_string(), Value::from(2));
// Iteration maintains insertion order
let keys: Vec<_> = map.keys().cloned().collect();
assert_eq!(keys, vec!["first", "second"]);Implementations§
Source§impl ToonMap
impl ToonMap
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty ToonMap.
§Examples
use serde_toon::ToonMap;
let map = ToonMap::new();
assert!(map.is_empty());Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates an empty ToonMap with the specified capacity.
§Examples
use serde_toon::ToonMap;
let map = ToonMap::with_capacity(10);
assert!(map.is_empty());Sourcepub fn insert(&mut self, key: String, value: Value) -> Option<Value>
pub fn insert(&mut self, key: String, value: Value) -> Option<Value>
Inserts a key-value pair into the map.
If the map already contained this key, the old value is returned.
§Examples
use serde_toon::{ToonMap, Value};
let mut map = ToonMap::new();
assert!(map.insert("key".to_string(), Value::from(42)).is_none());
assert!(map.insert("key".to_string(), Value::from(43)).is_some());Sourcepub fn get(&self, key: &str) -> Option<&Value>
pub fn get(&self, key: &str) -> Option<&Value>
Returns a reference to the value corresponding to the key.
§Examples
use serde_toon::{ToonMap, Value};
let mut map = ToonMap::new();
map.insert("key".to_string(), Value::from(42));
assert_eq!(map.get("key").and_then(|v| v.as_i64()), Some(42));Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the map.
§Examples
use serde_toon::{ToonMap, Value};
let mut map = ToonMap::new();
assert_eq!(map.len(), 0);
map.insert("key".to_string(), Value::from(42));
assert_eq!(map.len(), 1);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the map contains no elements.
§Examples
use serde_toon::ToonMap;
let map = ToonMap::new();
assert!(map.is_empty());Sourcepub fn keys(&self) -> Keys<'_, String, Value>
pub fn keys(&self) -> Keys<'_, String, Value>
Returns an iterator over the keys of the map, in insertion order.
Trait Implementations§
Source§impl IntoIterator for ToonMap
impl IntoIterator for ToonMap
impl StructuralPartialEq for ToonMap
Auto Trait Implementations§
impl Freeze for ToonMap
impl RefUnwindSafe for ToonMap
impl Send for ToonMap
impl Sync for ToonMap
impl Unpin for ToonMap
impl UnwindSafe for ToonMap
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
Mutably borrows from an owned value. Read more