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: AtomicUsizeImplementations§
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 &mut KvSize
For mutable references, the size can be directly updated.
impl GenericKvSize for &mut KvSize
For mutable references, the size can be directly updated.
fn update_size(&mut self, from: usize, to: usize)
Source§impl GenericKvSize for &KvSize
For immutable references, the size is updated atomically.
impl GenericKvSize for &KvSize
For immutable references, the size is updated atomically.
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 UnsafeUnpin 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