Struct unbounded_spsc::Sender

source ·
pub struct Sender<T> { /* private fields */ }

Implementations§

source§

impl<T> Sender<T>

source

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

Non-blocking send.

Examples found in repository?
examples/sequential-recv.rs (line 20)
16
17
18
19
20
21
22
23
24
25
26
27
28
fn sendfun (sender : unbounded_spsc::Sender <Mystruct>) {
  let mut counter = 0;
  let start_time = std::time::SystemTime::now();
  while counter < MESSAGE_COUNT {
    sender.send (Mystruct { x: counter as f64, y: 1.5, z: 2.0 }).unwrap();
    counter += 1;
  }
  let duration = start_time.elapsed().unwrap();
  let duration_ns
    = (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
  println!("sendfun duration ns: {}", duration_ns);
  println!("sendfun ns per message: {}", duration_ns / MESSAGE_COUNT);
}
More examples
Hide additional examples
examples/sequential-try_recv.rs (line 20)
16
17
18
19
20
21
22
23
24
25
26
27
28
fn sendfun (sender : unbounded_spsc::Sender <Mystruct>) {
  let mut counter = 0;
  let start_time = std::time::SystemTime::now();
  while counter < MESSAGE_COUNT {
    sender.send (Mystruct { x: counter as f64, y: 1.5, z: 2.0 }).unwrap();
    counter += 1;
  }
  let duration = start_time.elapsed().unwrap();
  let duration_ns
    = (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
  println!("sendfun duration ns: {}", duration_ns);
  println!("sendfun ns per message: {}", duration_ns / MESSAGE_COUNT);
}
examples/parallel-recv.rs (line 28)
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
fn sendfun (sender : unbounded_spsc::Sender <Mystruct>) {
  let mut counter = 0;
  SENDER_STARTED.store (true, std::sync::atomic::Ordering::SeqCst);
  // spin until receiver is started
  while !RECEIVER_STARTED.load (std::sync::atomic::Ordering::SeqCst) {}
  let start_time = std::time::SystemTime::now();
  while counter < MESSAGE_COUNT {
    sender.send (Mystruct { x: counter as f64, y: 1.5, z: 2.0 }).unwrap();
    counter += 1;
  }
  let duration = start_time.elapsed().unwrap();
  let duration_ns
    = (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
  println!("sendfun duration ns: {}", duration_ns);
  println!("sendfun ns per message: {}", duration_ns / MESSAGE_COUNT);
}
examples/parallel-try_recv.rs (line 28)
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
fn sendfun (sender : unbounded_spsc::Sender <Mystruct>) {
  let mut counter = 0;
  SENDER_STARTED.store (true, std::sync::atomic::Ordering::SeqCst);
  // spin until receiver is started
  while !RECEIVER_STARTED.load (std::sync::atomic::Ordering::SeqCst) {}
  let start_time = std::time::SystemTime::now();
  while counter < MESSAGE_COUNT {
    sender.send (Mystruct { x: counter as f64, y: 1.5, z: 2.0 }).unwrap();
    counter += 1;
  }
  let duration = start_time.elapsed().unwrap();
  let duration_ns
    = (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
  println!("sendfun duration ns: {}", duration_ns);
  println!("sendfun ns per message: {}", duration_ns / MESSAGE_COUNT);
}

Trait Implementations§

source§

impl<T> Debug for Sender<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> Drop for Sender<T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for Sender<T>

§

impl<T> Send for Sender<T>where T: Send,

§

impl<T> !Sync for Sender<T>

§

impl<T> Unpin for Sender<T>

§

impl<T> !UnwindSafe for Sender<T>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.