pub struct UnreliableBincodeChannel<R, P> where
R: Runtime,
P: PacketPool, { /* private fields */ }
Expand description
Wraps an UnreliableChannel
together with an internal buffer to allow easily sending message
types serialized with bincode
.
Just like the underlying channel, messages are not guaranteed to arrive, nor are they guaranteed to arrive in order.
Implementations
sourceimpl<R, P> UnreliableBincodeChannel<R, P> where
R: Runtime,
P: PacketPool,
impl<R, P> UnreliableBincodeChannel<R, P> where
R: Runtime,
P: PacketPool,
sourcepub fn new(channel: UnreliableChannel<R, P>, max_message_len: u16) -> Self
pub fn new(channel: UnreliableChannel<R, P>, max_message_len: u16) -> Self
Create a new UnreliableBincodeChannel
with the given max message size.
The maximum message size is always limited by the underlying UnreliableChannel
maximum
message size regardless of the max_message_len
setting, but this can be used to restrict
the intermediate buffer used to serialize messages.
sourcepub async fn send<T: Serialize>(&mut self, msg: &T) -> Result<(), SendError>
pub async fn send<T: Serialize>(&mut self, msg: &T) -> Result<(), SendError>
Write the given serializable message type to the channel.
Messages are coalesced into larger packets before being sent, so in order to guarantee that
the message is actually sent, you must call flush
.
This method is cancel safe, it will never partially send a message, though canceling it may or may not buffer a message to be sent.
sourcepub async fn flush(&mut self) -> Result<(), SendError>
pub async fn flush(&mut self) -> Result<(), SendError>
Finish sending any unsent coalesced packets.
This must be called to guarantee that any sent messages are actually sent to the outgoing packet stream.
This method is cancel safe.
sourcepub async fn recv<'a, T: Deserialize<'a>>(&'a mut self) -> Result<T, RecvError>
pub async fn recv<'a, T: Deserialize<'a>>(&'a mut self) -> Result<T, RecvError>
Receive a deserializable message type as soon as the next message is available.
This method is cancel safe, it will never partially read a message or drop received messages.
Auto Trait Implementations
impl<R, P> !RefUnwindSafe for UnreliableBincodeChannel<R, P>
impl<R, P> Send for UnreliableBincodeChannel<R, P> where
P: Send,
<P as PacketPool>::Packet: Send,
impl<R, P> Sync for UnreliableBincodeChannel<R, P> where
P: Sync,
<P as PacketPool>::Packet: Send + Sync,
impl<R, P> Unpin for UnreliableBincodeChannel<R, P> where
P: Unpin,
<P as PacketPool>::Packet: Unpin,
impl<R, P> !UnwindSafe for UnreliableBincodeChannel<R, P>
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