ToonMap

Struct ToonMap 

Source
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

Source

pub fn new() -> Self

Creates an empty ToonMap.

§Examples
use serde_toon::ToonMap;

let map = ToonMap::new();
assert!(map.is_empty());
Source

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());
Source

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());
Source

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));
Source

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);
Source

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());
Source

pub fn keys(&self) -> Keys<'_, String, Value>

Returns an iterator over the keys of the map, in insertion order.

Source

pub fn values(&self) -> Values<'_, String, Value>

Returns an iterator over the values of the map, in insertion order.

Source

pub fn iter(&self) -> Iter<'_, String, Value>

Returns an iterator over the key-value pairs of the map, in insertion order.

Trait Implementations§

Source§

impl Clone for ToonMap

Source§

fn clone(&self) -> ToonMap

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ToonMap

Source§

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

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

impl Default for ToonMap

Source§

fn default() -> Self

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

impl From<HashMap<String, Value>> for ToonMap

Source§

fn from(map: HashMap<String, Value>) -> Self

Converts to this type from the input type.
Source§

impl From<ToonMap> for HashMap<String, Value>

Source§

fn from(map: ToonMap) -> Self

Converts to this type from the input type.
Source§

impl From<ToonMap> for Value

Source§

fn from(value: ToonMap) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<(String, Value)> for ToonMap

Source§

fn from_iter<T: IntoIterator<Item = (String, Value)>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl IntoIterator for ToonMap

Source§

type Item = (String, Value)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<String, Value>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for ToonMap

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for ToonMap

Auto Trait Implementations§

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.