DynSender

Struct DynSender 

Source
pub struct DynSender<A, W = ()> { /* private fields */ }
Expand description

A wrapper around a Box<dyn DynSends> that allows for type-checked conversions.

Any sender can be converted into a DynSender, as long as the protocol it sends implements DynFromInto and marker traits AsSet. This conversion is type-checked, so that it is impossible to create DynSenders that send messages not accepted by the protocol.

§Sending

A DynSender automatically implements Sends<M> for all messages M accepted by the protocol. This means that you can just use a DynSender instead of a statically typed sender in most cases. If you need to send a message that is not accepted by the protocol, you can use the dyn_{...}-send methods, which return an error if the message is not accepted.

§Generics

The parameter A specifies the accepted messages of the dynamic sender. It can be specified using the Set or the DynSender macros:

  • DynSender<Set![]> == DynSender![]
  • DynSender<Set![Msg1, Msg2]> == DynSender![Msg1, Msg2]

§Unchecked methods

The unchecked methods, not marked unsafe, allow creating of DynSenders that send messages not accepted by the protocol. Only use these methods if you are sure that the protocol accepts the messages you send. If you are not sure, use the try_transform methods instead, which return an error if the protocol does not accept the messages.

Implementations§

Source§

impl<A, W> DynSender<A, W>

Source

pub fn new<S>(sender: S) -> Self
where S: SendsProtocol + DynSends<With = W>, A: SubsetOf<S::Protocol>,

Create a new DynSender from a statically typed sender.

Source

pub fn new_unchecked<S>(sender: S) -> Self
where S: DynSends<With = W>,

Create a new DynSender from a statically typed sender, without checking if the protocol accepts the messages.

Source

pub fn transform<A2>(self) -> DynSender<A2, W>
where A2: SubsetOf<A>,

Transform the DynSender into a DynSender that accepts a subset of the messages.

Source

pub fn try_transform<A2>(self) -> Result<DynSender<A2, W>, Self>
where A2: Members, W: 'static, A: 'static,

Attempt to transform the DynSender into a DynSender that accepts a subset of the messages, failing if the protocol does not accept the messages.

Source

pub fn transform_unchecked<A2>(self) -> DynSender<A2, W>

Transform the DynSender into a DynSender that accepts a subset of the messages, without checking if the protocol accepts the messages.

Source

pub fn from_boxed_unchecked(sender: Box<dyn DynSends<With = W>>) -> Self

Convert a Box<dyn DynSends> into a DynSender, without checking if the protocol accepts the messages.

Source

pub fn into_boxed_sender(self) -> Box<dyn DynSends<With = W>>

Convert into a Box<dyn DynSends>.

Source

pub fn downcast_ref<S>(&self) -> Option<&S>
where S: IsSender<With = W> + 'static, W: 'static,

Downcast the inner sender to a statically typed sender.

Trait Implementations§

Source§

impl<A, W: 'static> Clone for DynSender<A, W>

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
Source§

impl<A, W: Debug> Debug for DynSender<A, W>

Source§

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

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

impl<A, W> DynSends for DynSender<A, W>
where A: 'static, W: 'static,

Source§

fn dyn_send_boxed_msg_with( &self, msg: BoxedMsg<Self::With>, ) -> BoxFuture<'_, Result<(), DynSendError<BoxedMsg<Self::With>>>>

Source§

fn dyn_send_boxed_msg_blocking_with( &self, msg: BoxedMsg<Self::With>, ) -> Result<(), DynSendError<BoxedMsg<Self::With>>>

Source§

fn dyn_try_send_boxed_msg_with( &self, msg: BoxedMsg<Self::With>, ) -> Result<(), DynTrySendError<BoxedMsg<Self::With>>>

Source§

fn members(&self) -> &'static [TypeId]

Source§

fn clone_boxed(&self) -> Box<dyn DynSends<With = Self::With>>

Source§

fn as_any(&self) -> &dyn Any

Source§

impl<A, W> IsSender for DynSender<A, W>

Source§

type With = W

The value that must be passed along when sending a message.
Source§

fn is_closed(&self) -> bool

Returns true if the channel is closed.
Source§

fn capacity(&self) -> Option<usize>

Returns the capacity of the channel, if it is bounded.
Source§

fn len(&self) -> usize

Returns the number of messages in the channel.
Source§

fn receiver_count(&self) -> usize

Returns the number of receivers in the channel.
Source§

fn sender_count(&self) -> usize

Returns the number of senders in the channel.
Source§

impl<A, W, M> Sends<M> for DynSender<A, W>
where A: Contains<M>, M: Send + 'static, W: Send + 'static,

Source§

fn send_msg_with( this: &Self, msg: M, with: Self::With, ) -> impl Future<Output = Result<(), SendError<(M, Self::With)>>> + Send

Source§

fn try_send_msg_with( this: &Self, msg: M, with: Self::With, ) -> Result<(), TrySendError<(M, Self::With)>>

Source§

fn send_msg_blocking_with( this: &Self, msg: M, with: Self::With, ) -> Result<(), SendError<(M, Self::With)>>

Auto Trait Implementations§

§

impl<A, W> Freeze for DynSender<A, W>

§

impl<A, W = ()> !RefUnwindSafe for DynSender<A, W>

§

impl<A, W> Send for DynSender<A, W>

§

impl<A, W = ()> !Sync for DynSender<A, W>

§

impl<A, W> Unpin for DynSender<A, W>

§

impl<A, W = ()> !UnwindSafe for DynSender<A, W>

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> DynSendsExt for T
where T: DynSends,

Source§

fn accepts(&self, msg_id: TypeId) -> bool

Check if the sender accepts a message.
Source§

fn into_boxed(self) -> Box<dyn DynSends<With = Self::With>>
where Self: Sized,

Convert the sender into a boxed sender.
Source§

fn into_dyn<A>(self) -> DynSender<A, Self::With>
where Self: SendsProtocol, A: SubsetOf<Self::Protocol>,

Convert the sender into a DynSender.
Source§

fn into_dyn_unchecked<A>(self) -> DynSender<A, Self::With>
where Self: SendsProtocol,

Convert the sender into a DynSender, without checking if the protocol accepts the messages.
Source§

fn with(self, with: Self::With) -> WithValueSender<Self>
where Self: SendsProtocol, Self::With: Clone,

Map the with value of the sender to (), by providing the default with to use.
Source§

fn map_with<W>( self, f1: fn(W) -> Self::With, f2: fn(Self::With) -> W, ) -> MappedWithSender<Self, W>
where Self: SendsProtocol + Send + Sync,

Map the with value of the sender to W, by providing conversion functions.
Source§

fn dyn_send_msg_with<M>( &self, msg: M, with: Self::With, ) -> impl Future<Output = Result<(), DynSendError<(M, Self::With)>>> + Send
where M: Send + 'static, Self::With: Send + 'static,

Like SendsExt::send_msg_with, but fails if the message is not accepted by the protocol.
Source§

fn dyn_send_msg_blocking_with<M>( &self, msg: M, with: Self::With, ) -> Result<(), DynSendError<(M, Self::With)>>
where M: Send + 'static, Self::With: Send + 'static,

Like SendsExt::send_msg_blocking_with, but fails if the message is not accepted by the protocol.
Source§

fn dyn_try_send_msg_with<M>( &self, msg: M, with: Self::With, ) -> Result<(), DynTrySendError<(M, Self::With)>>
where M: Send + 'static, Self::With: Send + 'static,

Like SendsExt::try_send_msg_with, but fails if the message is not accepted by the protocol.
Source§

fn dyn_send_msg<M>( &self, msg: M, ) -> impl Future<Output = Result<(), DynSendError<M>>> + Send
where M: Send + 'static, Self::With: Default + Send + 'static,

Like SendsExt::send_with, but fails if the message is not accepted by the protocol.
Source§

fn dyn_send_msg_blocking<M>(&self, msg: M) -> Result<(), DynSendError<M>>
where M: Send + 'static, Self::With: Default + Send + 'static,

Like SendsExt::send_blocking_with, but fails if the message is not accepted by the protocol.
Source§

fn dyn_try_send_msg<M>(&self, msg: M) -> Result<(), DynTrySendError<M>>
where M: Send + 'static, Self::With: Default + Send + 'static,

Like SendsExt::try_send_msg_with, but fails if the message is not accepted by the protocol.
Source§

fn dyn_send_with<M>( &self, msg: impl Into<M::Input>, with: Self::With, ) -> impl Future<Output = Result<M::Output, DynSendError<(M::Input, Self::With)>>> + Send
where M: Send + 'static + Message, Self::With: Send + 'static, M::Output: Send,

Like SendsExt::send_with, but fails if the message is not accepted by the protocol.
Source§

fn dyn_send_blocking_with<M>( &self, msg: impl Into<M::Input>, with: Self::With, ) -> Result<M::Output, DynSendError<(M::Input, Self::With)>>
where M: Send + 'static + Message, Self::With: Send + 'static, M::Output: Send,

Like SendsExt::send_blocking_with, but fails if the message is not accepted by the protocol.
Source§

fn dyn_try_send_with<M>( &self, msg: impl Into<M::Input>, with: Self::With, ) -> Result<M::Output, DynTrySendError<(M::Input, Self::With)>>
where M: Send + 'static + Message, Self::With: Send + 'static, M::Output: Send,

Like SendsExt::try_send_with, but fails if the message is not accepted by the protocol.
Source§

fn dyn_send<M>( &self, msg: impl Into<M::Input>, ) -> impl Future<Output = Result<M::Output, DynSendError<M::Input>>> + Send
where M: Send + 'static + Message, Self::With: Default + Send + 'static, M::Output: Send,

Like SendsExt::send_with, but fails if the message is not accepted by the protocol.
Source§

fn dyn_send_blocking<M>( &self, msg: impl Into<M::Input>, ) -> Result<M::Output, DynSendError<M::Input>>
where M: Send + 'static + Message, Self::With: Default + Send + 'static, M::Output: Send,

Like SendsExt::send_blocking_with, but fails if the message is not accepted by the protocol.
Source§

fn dyn_try_send<M>( &self, msg: impl Into<M::Input>, ) -> Result<M::Output, DynTrySendError<M::Input>>
where M: Send + 'static + Message, Self::With: Default + Send + 'static, M::Output: Send,

Like SendsExt::try_send_with, but fails if the message is not accepted by the protocol.
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> SendsExt for T
where T: IsSender + ?Sized,

Source§

fn send_msg_with<M>( &self, msg: M, with: Self::With, ) -> impl Future<Output = Result<(), SendError<(M, Self::With)>>> + Send
where Self: Sends<M>,

Send a message with a custom value, waiting asynchronously until space becomes available. Read more
Source§

fn send_msg_blocking_with<M>( &self, msg: M, with: Self::With, ) -> Result<(), SendError<(M, Self::With)>>
where Self: Sends<M>,

Send a message with a custom value, blocking the current thread until space becomes available. Read more
Source§

fn try_send_msg_with<M>( &self, msg: M, with: Self::With, ) -> Result<(), TrySendError<(M, Self::With)>>
where Self: Sends<M>,

Send a message with a custom value, returning an error if space is not available. Read more
Source§

fn send_msg<M: Message>( &self, msg: M, ) -> impl Future<Output = Result<(), SendError<M>>> + Send
where Self: Sends<M>, Self::With: Default,

Send a message using a default value, waiting asynchronously until space becomes available. Read more
Source§

fn send_msg_blocking<M: Message>(&self, msg: M) -> Result<(), SendError<M>>
where Self: Sends<M>, Self::With: Default,

Send a message using a default value, blocking the current thread until space becomes available. Read more
Source§

fn try_send_msg<M: Message>(&self, msg: M) -> Result<(), TrySendError<M>>
where Self: Sends<M>, Self::With: Default,

Send a message using a default value, returning an error if space is not available. Read more
Source§

fn send_with<M: Message>( &self, msg: impl Into<M::Input>, with: Self::With, ) -> impl Future<Output = Result<M::Output, SendError<(M::Input, Self::With)>>> + Send
where Self: Sends<M>, M::Output: Send,

Send a message with a custom value, waiting asynchronously until space becomes available. Read more
Source§

fn send_blocking_with<M: Message>( &self, msg: impl Into<M::Input>, with: Self::With, ) -> Result<M::Output, SendError<(M::Input, Self::With)>>
where Self: Sends<M>,

Send a message with a custom value, blocking the current thread until space becomes available. Read more
Source§

fn try_send_with<M: Message>( &self, msg: impl Into<M::Input>, with: Self::With, ) -> Result<M::Output, TrySendError<(M::Input, Self::With)>>
where Self: Sends<M>,

Send a message with a custom value, returning an error if space is not available. Read more
Source§

fn send<M: Message>( &self, msg: impl Into<M::Input>, ) -> impl Future<Output = Result<M::Output, SendError<M::Input>>> + Send
where Self: Sends<M>, Self::With: Default,

Send a message using a default value, waiting asynchronously until space becomes available. Read more
Source§

fn send_blocking<M: Message>( &self, msg: impl Into<M::Input>, ) -> Result<M::Output, SendError<M::Input>>
where Self: Sends<M>, Self::With: Default,

Send a message using a default value, blocking the current thread until space becomes available. Read more
Source§

fn try_send<M: Message>( &self, msg: impl Into<M::Input>, ) -> Result<M::Output, TrySendError<M::Input>>
where Self: Sends<M>, Self::With: Default,

Send a message using a default value, returning an error if space is not available. Read more
Source§

fn request_with<M: Message>( &self, msg: impl Into<M::Input>, with: Self::With, ) -> impl Future<Output = Result<<M::Output as ResultFuture>::Ok, RequestError<(M::Input, Self::With), <M::Output as ResultFuture>::Error>>> + Send
where Self: Sends<M>, M::Output: ResultFuture,

Send a message with a custom value, waiting asynchronously until space becomes available, and then await the Message::Output. Read more
Source§

fn request<M: Message>( &self, msg: impl Into<M::Input>, ) -> impl Future<Output = Result<<M::Output as ResultFuture>::Ok, RequestError<M::Input, <M::Output as ResultFuture>::Error>>> + Send
where Self: Sends<M>, Self::With: Default, M::Output: ResultFuture,

Send a message using a default value, blocking the current thread until space becomes available, and then await the Message::Output. Read more
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.
Source§

impl<T, S> SupersetOf<S> for T
where S: SubsetOf<T>,

Source§

impl<S> Zero for S
where S: ?Sized,