Macro id_ord_map

Source
macro_rules! id_ord_map {
    ($($item:expr,)+) => { ... };
    ($($item:expr),*) => { ... };
}
Expand description

Creates an IdOrdMap from a list of items.

§Panics

Panics if the list of items has duplicate keys. For better error handling, the item is required to implement Debug.

§Examples

use iddqd::{IdOrdItem, id_ord_map, id_upcast};

#[derive(Debug)]
struct User {
    id: u32,
    name: String,
}

impl IdOrdItem for User {
    type Key<'a> = u32;
    fn key(&self) -> Self::Key<'_> {
        self.id
    }
    id_upcast!();
}

let map = id_ord_map! {
    User { id: 1, name: "Alice".to_string() },
    User { id: 2, name: "Bob".to_string() },
};
assert_eq!(map.get(&1).unwrap().name, "Alice");
assert_eq!(map.get(&2).unwrap().name, "Bob");