#![doc = include_str!("../README.md")]
#![cfg_attr(not(feature = "std"), no_std)]
use self::compat::*;
pub mod ptr_weak_hash_set;
pub mod ptr_weak_key_hash_map;
pub mod ptr_weak_weak_hash_map;
pub mod traits;
pub mod weak_hash_set;
pub mod weak_key_hash_map;
pub mod weak_value_hash_map;
pub mod weak_weak_hash_map;
#[cfg(test)]
mod tests;
mod by_ptr;
mod common;
mod compat;
mod inner;
mod size_policy;
mod util;
#[derive(Clone)]
pub struct WeakKeyHashMap<K, V, S = RandomState>(inner::Table<inner::WeakK<K>, inner::Owned<V>, S>);
#[derive(Clone)]
pub struct PtrWeakKeyHashMap<K, V, S = RandomState>(WeakKeyHashMap<by_ptr::ByPtr<K>, V, S>);
#[derive(Clone)]
pub struct WeakValueHashMap<K, V, S = RandomState>(
inner::Table<inner::Owned<K>, inner::WeakV<V>, S>,
);
#[derive(Clone)]
pub struct WeakWeakHashMap<K, V, S = RandomState>(
inner::Table<inner::WeakK<K>, inner::WeakV<V>, S>,
);
#[derive(Clone)]
pub struct PtrWeakWeakHashMap<K, V, S = RandomState>(WeakWeakHashMap<by_ptr::ByPtr<K>, V, S>);
#[derive(Clone)]
pub struct WeakHashSet<T, S = RandomState>(WeakKeyHashMap<T, (), S>);
#[derive(Clone)]
pub struct PtrWeakHashSet<T, S = RandomState>(PtrWeakKeyHashMap<T, (), S>);
#[derive(Clone, Debug)]
#[non_exhaustive]
pub enum TryReserveError {
CapacityOverflow,
AllocError {
layout: Layout,
},
}
impl TryReserveError {
#[allow(clippy::needless_pass_by_value)]
pub(crate) fn from_hashbrown(error: hashbrown::TryReserveError) -> Self {
match error {
hashbrown::TryReserveError::CapacityOverflow => TryReserveError::CapacityOverflow,
hashbrown::TryReserveError::AllocError { layout } => {
TryReserveError::AllocError { layout }
}
}
}
}
impl Display for TryReserveError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
TryReserveError::CapacityOverflow => write!(
f,
"Allocation failed: arithmetic overflow in capacity calculation"
),
TryReserveError::AllocError { .. } => {
write!(f, "Allocation failed: memory allocator returned an error")
}
}
}
}
#[cfg(feature = "std")]
impl Error for TryReserveError {}