pub struct KvSize(pub(crate) AtomicUsize);
Expand description
The size of the collection.
We use an atomic value here to enable operating the size without a mutable reference.
See collections::AtomicMutGuard
for more details.
In the most cases, we have the mutable reference of this struct, so we can directly operate the underlying value.
Tuple Fields§
§0: AtomicUsize
Implementations§
source§impl KvSize
impl KvSize
pub fn new() -> Self
pub fn with_size(size: usize) -> Self
pub fn add<K: EstimateSize, V: EstimateSize>(&mut self, key: &K, val: &V)
pub fn sub<K: EstimateSize, V: EstimateSize>(&mut self, key: &K, val: &V)
sourcepub fn add_val<V: EstimateSize>(&mut self, val: &V) -> usize
pub fn add_val<V: EstimateSize>(&mut self, val: &V) -> usize
Add the size of val
and return it.
pub fn sub_val<V: EstimateSize>(&mut self, val: &V)
pub fn add_size(&mut self, size: usize)
pub fn sub_size(&mut self, size: usize)
sourcepub fn update_size_atomic(&self, from: usize, to: usize)
pub fn update_size_atomic(&self, from: usize, to: usize)
Update the size of the collection by to - from
atomically, i.e., without a mutable reference.
pub fn set(&mut self, size: usize)
pub fn size(&self) -> usize
Trait Implementations§
source§impl GenericKvSize for &KvSize
impl GenericKvSize for &KvSize
For immutable references, the size is updated atomically.
fn update_size(&mut self, from: usize, to: usize)
source§impl GenericKvSize for &mut KvSize
impl GenericKvSize for &mut KvSize
For mutable references, the size can be directly updated.
fn update_size(&mut self, from: usize, to: usize)
Auto Trait Implementations§
impl !Freeze for KvSize
impl RefUnwindSafe for KvSize
impl Send for KvSize
impl Sync for KvSize
impl Unpin for KvSize
impl UnwindSafe for KvSize
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)