Control

Struct Control 

Source
pub struct Control<T, U>
where T: 'static,
{ /* private fields */ }
Expand description

Controls the collection and accumulation of thread-local variables linked to this object.

T is the type of the values sent on the channel to this object and U is the type of the accumulated value. The thread-locals must be of type Holder<T>.

Implementations§

Source§

impl<T, U> Control<T, U>

Source

pub fn new( tl: &'static LocalKey<Holder<T>>, acc_base: U, op: impl Fn(T, &mut U, ThreadId) + 'static + Send + Sync, ) -> Self

Instantiates a Control object.

  • tl - reference to thread-local static.
  • acc_base - initial value for accumulation.
  • op - operation that combines data from thread-locals with accumulated value.
Source

pub fn acc(&self) -> impl Deref<Target = U> + '_

Returns a guard object that dereferences to self’s accumulated value. A lock is held during the guard’s lifetime.

§Panics

If self’s mutex is poisoned.

Source

pub fn with_acc<V>(&self, f: impl FnOnce(&U) -> V) -> V

Provides access to self’s accumulated value.

§Panics

If self’s mutex is poisoned.

Source

pub fn clone_acc(&self) -> U
where U: Clone,

Returns a clone of self’s accumulated value.

§Panics

If self’s mutex is poisoned.

Source

pub fn take_acc(&self, replacement: U) -> U

Returns self’s accumulated value, using a value of the same type to replace the existing accumulated value.

§Panics

If self’s mutex is poisoned.

Source

pub fn start_receiving_tls(&self) -> Result<(), MultipleReceiverThreadsError>
where T: 'static + Send, U: 'static + Send,

Spawns a background thread to receive thread-local values and aggregate them with this object’s accumulated value. May be called repeatedly, provided that there are intervening calls to Self::stop_receiving_tls or Self::drain_tls.

§Errors

Returns an error if there is already an active background receiver thread.

§Panics

If self’s mutex is poisoned.

Source

pub fn stop_receiving_tls(&self)

Signals the background receiving thread to terminate itself.

Source

pub fn drain_tls(&self)

Receives all pending messages in channel and aggregates the corresponding values, terminating the background thread if it exists. May be called repeatedly, even before participating theads have terminated.

§Panics

If self’s mutex is poisoned.

Source

pub fn send_data(&self, data: T)

Sends data from the thread where it is called to be accumulated by the Control instance;

Trait Implementations§

Source§

impl<T, U> Clone for Control<T, U>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<T, U> Freeze for Control<T, U>

§

impl<T, U> !RefUnwindSafe for Control<T, U>

§

impl<T, U> Send for Control<T, U>
where T: Send, U: Send,

§

impl<T, U> Sync for Control<T, U>
where T: Send, U: Send,

§

impl<T, U> Unpin for Control<T, U>

§

impl<T, U> !UnwindSafe for Control<T, U>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.