Struct btmsg::Transmitter
source · pub struct Transmitter { /* private fields */ }
Expand description
A type which can be used to transmit messages over the network to a crate::Receiver.
Implementations§
source§impl Transmitter
impl Transmitter
pub async fn new<C: 'static + Creds + Send + Sync>( addr: Arc<BlockAddr>, creds: Arc<C> ) -> Result<Transmitter>
sourcepub fn addr(&self) -> &Arc<BlockAddr>
pub fn addr(&self) -> &Arc<BlockAddr>
Returns the address that this instance is transmitting to.
sourcepub async fn send<'ser, 'de, T>(&self, msg: T) -> Result<()>where
T: 'ser + SendMsg<'de>,
pub async fn send<'ser, 'de, T>(&self, msg: T) -> Result<()>where T: 'ser + SendMsg<'de>,
Transmit a message to the connected crate::Receiver without waiting for a reply.
sourcepub async fn call<'ser, 'de, T, F>(
&self,
msg: T,
callback: F
) -> Result<F::Return>where
T: 'ser + CallMsg<'de>,
F: 'static + Send + DeserCallback,
pub async fn call<'ser, 'de, T, F>( &self, msg: T, callback: F ) -> Result<F::Return>where T: 'ser + CallMsg<'de>, F: 'static + Send + DeserCallback,
Transmit a message to the connected crate::Receiver, waits for a reply, then calls the given DeserCallback with the deserialized reply.
WARNING
The callback must be such that F::Arg<'a> = T::Reply<'a>
for any 'a
. If this
is violated, then a deserilization error will occur at runtime.
TODO
This issue needs to be fixed. Due to the fact that
F::Arg
is a Generic Associated Type (GAT) I have been unable to express this constraint in
the where clause of this method. I’m not sure if the errors I’ve encountered are due to a
lack of understanding on my part or due to the current limitations of the borrow checker in
its handling of GATs.
sourcepub async fn call_through<'ser, T>(&self, msg: T) -> Result<T::Reply<'static>>where
T: 'ser + CallMsg<'static>,
T::Reply<'static>: 'static + Send + Sync + DeserializeOwned,
pub async fn call_through<'ser, T>(&self, msg: T) -> Result<T::Reply<'static>>where T: 'ser + CallMsg<'static>, T::Reply<'static>: 'static + Send + Sync + DeserializeOwned,
Transmits a message to the connected crate::Receiver, waits for a reply, then passes back the
the reply to the caller. This only works for messages whose reply doesn’t borrow any data,
otherwise the call
method must be used.