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>
impl<A, W> DynSender<A, W>
Sourcepub fn new_unchecked<S>(sender: S) -> Selfwhere
S: DynSends<With = W>,
pub fn new_unchecked<S>(sender: S) -> Selfwhere
S: DynSends<With = W>,
Create a new DynSender from a statically typed sender, without checking if the protocol
accepts the messages.
Sourcepub fn transform<A2>(self) -> DynSender<A2, W>where
A2: SubsetOf<A>,
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.
Sourcepub fn try_transform<A2>(self) -> Result<DynSender<A2, W>, Self>where
A2: Members,
W: 'static,
A: 'static,
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.
Sourcepub fn transform_unchecked<A2>(self) -> DynSender<A2, W>
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.
Sourcepub fn from_boxed_unchecked(sender: Box<dyn DynSends<With = W>>) -> Self
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.
Sourcepub fn into_boxed_sender(self) -> Box<dyn DynSends<With = W>>
pub fn into_boxed_sender(self) -> Box<dyn DynSends<With = W>>
Convert into a Box<dyn DynSends>.
Sourcepub fn downcast_ref<S>(&self) -> Option<&S>where
S: IsSender<With = W> + 'static,
W: 'static,
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> DynSends for DynSender<A, W>where
A: 'static,
W: 'static,
impl<A, W> DynSends for DynSender<A, W>where
A: 'static,
W: 'static,
fn dyn_send_boxed_msg_with( &self, msg: BoxedMsg<Self::With>, ) -> BoxFuture<'_, Result<(), DynSendError<BoxedMsg<Self::With>>>>
fn dyn_send_boxed_msg_blocking_with( &self, msg: BoxedMsg<Self::With>, ) -> Result<(), DynSendError<BoxedMsg<Self::With>>>
fn dyn_try_send_boxed_msg_with( &self, msg: BoxedMsg<Self::With>, ) -> Result<(), DynTrySendError<BoxedMsg<Self::With>>>
fn members(&self) -> &'static [TypeId]
fn clone_boxed(&self) -> Box<dyn DynSends<With = Self::With>>
fn as_any(&self) -> &dyn Any
Source§impl<A, W> IsSender for DynSender<A, W>
impl<A, W> IsSender for DynSender<A, W>
Source§fn receiver_count(&self) -> usize
fn receiver_count(&self) -> usize
Source§fn sender_count(&self) -> usize
fn sender_count(&self) -> usize
Source§impl<A, W, M> Sends<M> for DynSender<A, W>
impl<A, W, M> Sends<M> for DynSender<A, W>
fn send_msg_with( this: &Self, msg: M, with: Self::With, ) -> impl Future<Output = Result<(), SendError<(M, Self::With)>>> + Send
fn try_send_msg_with( this: &Self, msg: M, with: Self::With, ) -> Result<(), TrySendError<(M, Self::With)>>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DynSendsExt for Twhere
T: DynSends,
impl<T> DynSendsExt for Twhere
T: DynSends,
Source§fn into_boxed(self) -> Box<dyn DynSends<With = Self::With>>where
Self: Sized,
fn into_boxed(self) -> Box<dyn DynSends<With = Self::With>>where
Self: Sized,
Source§fn into_dyn_unchecked<A>(self) -> DynSender<A, Self::With>where
Self: SendsProtocol,
fn into_dyn_unchecked<A>(self) -> DynSender<A, Self::With>where
Self: SendsProtocol,
DynSender, without checking if the protocol accepts the messages.Source§fn with(self, with: Self::With) -> WithValueSender<Self>
fn with(self, with: Self::With) -> WithValueSender<Self>
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>
fn map_with<W>( self, f1: fn(W) -> Self::With, f2: fn(Self::With) -> W, ) -> MappedWithSender<Self, W>
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
fn dyn_send_msg_with<M>( &self, msg: M, with: Self::With, ) -> impl Future<Output = Result<(), DynSendError<(M, Self::With)>>> + Send
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)>>
fn dyn_send_msg_blocking_with<M>( &self, msg: M, with: Self::With, ) -> Result<(), DynSendError<(M, Self::With)>>
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)>>
fn dyn_try_send_msg_with<M>( &self, msg: M, with: Self::With, ) -> Result<(), DynTrySendError<(M, Self::With)>>
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
fn dyn_send_msg<M>( &self, msg: M, ) -> impl Future<Output = Result<(), DynSendError<M>>> + Send
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>>
fn dyn_send_msg_blocking<M>(&self, msg: M) -> Result<(), DynSendError<M>>
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>>
fn dyn_try_send_msg<M>(&self, msg: M) -> Result<(), DynTrySendError<M>>
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
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
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)>>
fn dyn_send_blocking_with<M>( &self, msg: impl Into<M::Input>, with: Self::With, ) -> Result<M::Output, DynSendError<(M::Input, Self::With)>>
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)>>
fn dyn_try_send_with<M>( &self, msg: impl Into<M::Input>, with: Self::With, ) -> Result<M::Output, DynTrySendError<(M::Input, Self::With)>>
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
fn dyn_send<M>( &self, msg: impl Into<M::Input>, ) -> impl Future<Output = Result<M::Output, DynSendError<M::Input>>> + Send
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>>
fn dyn_send_blocking<M>( &self, msg: impl Into<M::Input>, ) -> Result<M::Output, DynSendError<M::Input>>
SendsExt::send_blocking_with, but fails if the message is not accepted by the protocol.Source§impl<T> SendsExt for T
impl<T> SendsExt for T
Source§fn send_msg_with<M>(
&self,
msg: M,
with: Self::With,
) -> impl Future<Output = Result<(), SendError<(M, Self::With)>>> + Sendwhere
Self: Sends<M>,
fn send_msg_with<M>(
&self,
msg: M,
with: Self::With,
) -> impl Future<Output = Result<(), SendError<(M, Self::With)>>> + Sendwhere
Self: Sends<M>,
Source§fn send_msg_blocking_with<M>(
&self,
msg: M,
with: Self::With,
) -> Result<(), SendError<(M, Self::With)>>where
Self: Sends<M>,
fn send_msg_blocking_with<M>(
&self,
msg: M,
with: Self::With,
) -> Result<(), SendError<(M, Self::With)>>where
Self: Sends<M>,
Source§fn try_send_msg_with<M>(
&self,
msg: M,
with: Self::With,
) -> Result<(), TrySendError<(M, Self::With)>>where
Self: Sends<M>,
fn try_send_msg_with<M>(
&self,
msg: M,
with: Self::With,
) -> Result<(), TrySendError<(M, Self::With)>>where
Self: Sends<M>,
Source§fn send_msg<M: Message>(
&self,
msg: M,
) -> impl Future<Output = Result<(), SendError<M>>> + Send
fn send_msg<M: Message>( &self, msg: M, ) -> impl Future<Output = Result<(), SendError<M>>> + Send
Source§fn send_msg_blocking<M: Message>(&self, msg: M) -> Result<(), SendError<M>>
fn send_msg_blocking<M: Message>(&self, msg: M) -> Result<(), SendError<M>>
Source§fn try_send_msg<M: Message>(&self, msg: M) -> Result<(), TrySendError<M>>
fn try_send_msg<M: Message>(&self, msg: M) -> Result<(), TrySendError<M>>
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
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
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>,
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>,
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>,
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>,
Source§fn send<M: Message>(
&self,
msg: impl Into<M::Input>,
) -> impl Future<Output = Result<M::Output, SendError<M::Input>>> + Send
fn send<M: Message>( &self, msg: impl Into<M::Input>, ) -> impl Future<Output = Result<M::Output, SendError<M::Input>>> + Send
Source§fn send_blocking<M: Message>(
&self,
msg: impl Into<M::Input>,
) -> Result<M::Output, SendError<M::Input>>
fn send_blocking<M: Message>( &self, msg: impl Into<M::Input>, ) -> Result<M::Output, SendError<M::Input>>
Source§fn try_send<M: Message>(
&self,
msg: impl Into<M::Input>,
) -> Result<M::Output, TrySendError<M::Input>>
fn try_send<M: Message>( &self, msg: impl Into<M::Input>, ) -> Result<M::Output, TrySendError<M::Input>>
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
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
Message::Output. Read moreSource§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
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
Message::Output. Read more