[][src]Struct metrics_util::AtomicBucket

pub struct AtomicBucket<T> { /* fields omitted */ }

An atomic bucket with snapshot capabilities.

This bucket is implemented as a singly-linked list of blocks, where each block is a small buffer that can hold a handful of elements. There is no limit to how many elements can be in the bucket at a time. Blocks are dynamically allocated as elements are pushed into the bucket.

Unlike a queue, buckets cannot be drained element by element: callers must iterate the whole structure. Reading the bucket happens in reverse, to allow writers to make forward progress without affecting the iteration of the previously-written values.

The bucket can be cleared while a concurrent snapshot is taking place, and will not affect the reader.

Methods

impl<T> AtomicBucket<T>[src]

pub fn new() -> Self[src]

Creates a new, empty bucket.

pub fn push(&self, value: T)[src]

Pushes an element into the bucket.

pub fn data(&self) -> Vec<T> where
    T: Clone
[src]

Collects all of the elements written to the bucket.

This operation can be slow as it involves allocating enough space to hold all of the elements within the bucket. Consider data_with to incrementally iterate the internal blocks within the bucket.

Elements are in partial reverse order: blocks are iterated in reverse order, but the elements within them will appear in their original order.

pub fn data_with<F>(&self, f: F) where
    F: FnMut(&[T]), 
[src]

Iterates all of the elements written to the bucket, invoking f for each block.

Elements are in partial reverse order: blocks are iterated in reverse order, but the elements within them will appear in their original order.

pub fn clear(&self)[src]

Clears the bucket.

Deallocation of the internal blocks happens only when all readers have finished, and so will not necessarily occur during or immediately preceding this method.

Note

This method will not affect reads that are already in progress.

Trait Implementations

impl<T: Debug> Debug for AtomicBucket<T>[src]

Auto Trait Implementations

impl<T> Send for AtomicBucket<T>

impl<T> Sync for AtomicBucket<T>

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]