Struct librumqttd::rumqttlog::Sender
source · [−]pub struct Sender<T> { /* private fields */ }
Expand description
The sending side of a channel.
Senders can be cloned and shared among threads. When all senders associated with a channel are dropped, the channel becomes closed.
The channel can also be closed manually by calling Sender::close()
.
Implementations
sourceimpl<T> Sender<T>
impl<T> Sender<T>
sourcepub fn try_send(&self, msg: T) -> Result<(), TrySendError<T>>
pub fn try_send(&self, msg: T) -> Result<(), TrySendError<T>>
Attempts to send a message into the channel.
If the channel is full or closed, this method returns an error.
Examples
use jackiechan::{bounded, TrySendError};
let (s, r) = bounded(1);
assert_eq!(s.try_send(1), Ok(()));
assert_eq!(s.try_send(2), Err(TrySendError::Full(2)));
drop(r);
assert_eq!(s.try_send(3), Err(TrySendError::Closed(3)));
sourcepub fn send(&self, msg: T) -> Result<(), SendError<T>>
pub fn send(&self, msg: T) -> Result<(), SendError<T>>
Sends a message into the channel.
If the channel is full, this method waits until there is space for a message.
If the channel is closed, this method returns an error.
Examples
use jackiechan::{bounded, SendError};
let (s, r) = bounded(100);
assert_eq!(s.send(1), Ok(()));
drop(r);
assert_eq!(s.send(2), Err(SendError(2)));
sourcepub async fn async_send(&'_ self, msg: T) -> Result<(), SendError<T>>
pub async fn async_send(&'_ self, msg: T) -> Result<(), SendError<T>>
Sends a message into the channel.
If the channel is full, this method waits until there is space for a message.
If the channel is closed, this method returns an error.
Examples
use jackiechan::{bounded, SendError};
let (s, r) = bounded(100);
assert_eq!(s.async_send(1).await, Ok(()));
drop(r);
assert_eq!(s.async_send(2).await, Err(SendError(2)));
sourcepub fn close(&self) -> bool
pub fn close(&self) -> bool
Closes the channel.
Returns true
if this call has closed the channel and it was not closed already.
The remaining messages can still be received.
Examples
use jackiechan::{bounded, RecvError};
let (s, r) = bounded(10);
assert_eq!(s.send(1), Ok(()));
assert!(s.close());
assert_eq!(r.recv(), Ok(1));
assert_eq!(r.recv(), Err(RecvError));
sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
Returns true
if the channel is closed.
Examples
use jackiechan::{bounded, RecvError};
let (s, r) = bounded::<()>(10);
assert!(!s.is_closed());
s.close();
assert!(s.is_closed());
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if the channel is empty.
Examples
use jackiechan::bounded;
let (s, r) = bounded(10);
assert!(s.is_empty());
s.send(1);
assert!(!s.is_empty());
sourcepub fn is_full(&self) -> bool
pub fn is_full(&self) -> bool
Returns true
if the channel is full.
Unbounded channels are never full.
Examples
use jackiechan::bounded;
let (s, r) = bounded(1);
assert!(!s.is_full());
s.send(1);
assert!(s.is_full());
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of messages in the channel.
Examples
use jackiechan::bounded;
let (s, r) = bounded(10);
assert_eq!(s.len(), 0);
s.send(1);
s.send(2);
assert_eq!(s.len(), 2);
sourcepub fn capacity(&self) -> Option<usize>
pub fn capacity(&self) -> Option<usize>
Returns the channel capacity if it’s bounded.
Examples
use jackiechan::{bounded};
let (s, r) = bounded::<i32>(5);
assert_eq!(s.capacity(), Some(5));
sourcepub fn receiver_count(&self) -> usize
pub fn receiver_count(&self) -> usize
Returns the number of receivers for the channel.
Examples
use jackiechan::bounded;
let (s, r) = bounded::<()>(10);
assert_eq!(s.receiver_count(), 1);
let r2 = r.clone();
assert_eq!(s.receiver_count(), 2);
sourcepub fn sender_count(&self) -> usize
pub fn sender_count(&self) -> usize
Returns the number of senders for the channel.
Examples
use jackiechan::bounded;
let (s, r) = bounded::<()>(10);
assert_eq!(s.sender_count(), 1);
let s2 = s.clone();
assert_eq!(s.sender_count(), 2);
Trait Implementations
Auto Trait Implementations
impl<T> RefUnwindSafe for Sender<T>
impl<T> Send for Sender<T> where
T: Send,
impl<T> Sync for Sender<T> where
T: Send,
impl<T> Unpin for Sender<T>
impl<T> UnwindSafe for Sender<T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more