Announcement

Struct Announcement 

Source
pub struct Announcement<T> { /* private fields */ }
Expand description

The main announcement channel type that creates listeners.

This is the primary interface for creating listeners that will receive the announced value. It can be cloned cheaply to share across threads.

§Examples

use announcement::Announcement;

let (announcer, announcement) = Announcement::<i32>::new();
let listener1 = announcement.listener();
let listener2 = announcement.listener();

announcer.announce(42).unwrap();

assert_eq!(listener1.try_listen(), Some(42));
assert_eq!(listener2.try_listen(), Some(42));

Implementations§

Source§

impl<T: Clone + Send + Sync + 'static> Announcement<T>

Source

pub fn new() -> (Announcer<T>, Self)

Create a new announcement channel.

Returns a tuple of (Announcer, Announcement). The announcer is used to broadcast the value once, and the announcement is used to create listeners.

§Examples
use announcement::Announcement;

let (announcer, announcement) = Announcement::<i32>::new();
Source

pub fn listener(&self) -> Listener<T>

Create a new listener for this announcement.

Can be called before or after announcing. Can be called multiple times to create multiple independent listeners that will all receive the same value.

§Performance

O(1), performs 2 Arc clones (~10-20ns)

§Examples
use announcement::Announcement;

let (announcer, announcement) = Announcement::new();
let listener1 = announcement.listener();
let listener2 = announcement.listener();

announcer.announce(42).unwrap();

assert_eq!(listener1.try_listen(), Some(42));
assert_eq!(listener2.try_listen(), Some(42));
Source

pub fn is_announced(&self) -> bool

Check if a value has been announced.

This is a non-blocking, lock-free operation.

§Performance

O(1), ~5-10ns

§Examples
use announcement::Announcement;

let (announcer, announcement) = Announcement::<i32>::new();
assert!(!announcement.is_announced());

announcer.announce(42).unwrap();
assert!(announcement.is_announced());
Source

pub fn is_closed(&self) -> bool

Check if the announcer was closed without announcing.

Returns true if the announcer was explicitly closed or dropped without announcing. This is a non-blocking, lock-free operation.

§Performance

O(1), ~5-10ns

§Examples
use announcement::Announcement;

let (announcer, announcement) = Announcement::<i32>::new();
assert!(!announcement.is_closed());

drop(announcer);
assert!(announcement.is_closed());

Trait Implementations§

Source§

impl<T: Clone> Clone for Announcement<T>

Source§

fn clone(&self) -> Announcement<T>

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> Freeze for Announcement<T>

§

impl<T> RefUnwindSafe for Announcement<T>

§

impl<T> Send for Announcement<T>
where T: Sync + Send,

§

impl<T> Sync for Announcement<T>
where T: Sync + Send,

§

impl<T> Unpin for Announcement<T>

§

impl<T> UnwindSafe for Announcement<T>

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.