pub struct IdMap<K: Id, V> { /* private fields */ }Expand description
极简版 IdMap:自动生成递增 Id + HashMap 存储 + 无条件编译
Implementations§
Source§impl<V> IdMap<DefaultId, V>
impl<V> IdMap<DefaultId, V>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
创建指定初始容量的 IdMap
Source§impl<K: Id, V> IdMap<K, V>
impl<K: Id, V> IdMap<K, V>
Sourcepub fn with_id_capacity(capacity: usize) -> Self
pub fn with_id_capacity(capacity: usize) -> Self
自定义 Id 类型创建指定初始容量的 IdMap
Sourcepub fn insert_with_id(&mut self, id: K, value: V) -> Option<V>
pub fn insert_with_id(&mut self, id: K, value: V) -> Option<V>
【手动指定 Id】插入键值对,返回旧值(若存在)
注意:若手动传入的 Id 大于当前 max_id,会更新 max_id 以保证自动生成的 Id 不重复
Sourcepub fn from_vec(values: Vec<V>) -> (Self, Vec<K>)
pub fn from_vec(values: Vec<V>) -> (Self, Vec<K>)
从 Vec
Sourcepub fn insert_cyclic<F>(&mut self, f: F) -> Kwhere
F: FnOnce(K) -> V,
pub fn insert_cyclic<F>(&mut self, f: F) -> Kwhere
F: FnOnce(K) -> V,
循环插入:先生成递增 Id,再通过闭包(Id → V)生成值并插入 适用于值需要依赖自身 Id 的场景(如循环引用/关联 Id 的场景)
Sourcepub fn contains_id(&self, id: K) -> bool
pub fn contains_id(&self, id: K) -> bool
判断是否包含指定 Id
Trait Implementations§
Source§impl<'de, K: Id, V> Deserialize<'de> for IdMap<K, V>where
V: Deserialize<'de>,
impl<'de, K: Id, V> Deserialize<'de> for IdMap<K, V>where
V: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl<K, V> Freeze for IdMap<K, V>
impl<K, V> RefUnwindSafe for IdMap<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for IdMap<K, V>
impl<K, V> Sync for IdMap<K, V>
impl<K, V> Unpin for IdMap<K, V>
impl<K, V> UnsafeUnpin for IdMap<K, V>
impl<K, V> UnwindSafe for IdMap<K, V>where
V: UnwindSafe,
K: UnwindSafe,
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