Struct Sender

Source
pub struct Sender<T, const N: usize> { /* private fields */ }
Expand description

Sender half of the queue. Safe to share between threads.

Implementations§

Source§

impl<T, const N: usize> Sender<T, N>

Source

pub fn send(&self, item: T) -> Result<(), T>

Sends an item into the queue. The receive order of sent items is not guaranteed.

Examples found in repository?
examples/simple.rs (line 20)
7fn main() {
8    let (tx, mut rx) = FutexQueue::<u32, 4>::new();
9    let now = Instant::now();
10
11    let thread = thread::spawn(move || loop {
12        let item = rx.recv();
13        println!(
14            "{} ms: Received: {}",
15            now.elapsed().as_millis(),
16            item.value()
17        );
18    });
19
20    tx.send(1).unwrap();
21    tx.send_scheduled(2, now + Duration::from_secs(1)).unwrap();
22    tx.send(3).unwrap();
23    tx.send_scheduled(4, now + Duration::from_secs(2)).unwrap();
24
25    thread.join().unwrap();
26}
Source

pub fn send_scheduled(&self, item: T, instant: Instant) -> Result<(), T>

Puts item into a queue to be received at a specified instant. Receive order is earliest deadline first (after all immediate items).

Examples found in repository?
examples/simple.rs (line 21)
7fn main() {
8    let (tx, mut rx) = FutexQueue::<u32, 4>::new();
9    let now = Instant::now();
10
11    let thread = thread::spawn(move || loop {
12        let item = rx.recv();
13        println!(
14            "{} ms: Received: {}",
15            now.elapsed().as_millis(),
16            item.value()
17        );
18    });
19
20    tx.send(1).unwrap();
21    tx.send_scheduled(2, now + Duration::from_secs(1)).unwrap();
22    tx.send(3).unwrap();
23    tx.send_scheduled(4, now + Duration::from_secs(2)).unwrap();
24
25    thread.join().unwrap();
26}

Auto Trait Implementations§

§

impl<T, const N: usize> Freeze for Sender<T, N>

§

impl<T, const N: usize> RefUnwindSafe for Sender<T, N>

§

impl<T, const N: usize> Send for Sender<T, N>
where T: Send,

§

impl<T, const N: usize> Sync for Sender<T, N>
where T: Send,

§

impl<T, const N: usize> Unpin for Sender<T, N>

§

impl<T, const N: usize> UnwindSafe for Sender<T, N>

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> 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, 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.