pub struct AsyncWriteTyped<W: AsyncWrite + Unpin, T: Serialize + DeserializeOwned + Unpin> { /* private fields */ }
Expand description
Provides the ability to write serde
compatible types to any type that implements futures::io::AsyncWrite
.
Implementations§
Source§impl<W: AsyncWrite + Unpin, T: Serialize + DeserializeOwned + Unpin> AsyncWriteTyped<W, T>
impl<W: AsyncWrite + Unpin, T: Serialize + DeserializeOwned + Unpin> AsyncWriteTyped<W, T>
Sourcepub fn new_with_limit(
raw: W,
size_limit: u64,
checksum_enabled: ChecksumEnabled,
) -> Self
pub fn new_with_limit( raw: W, size_limit: u64, checksum_enabled: ChecksumEnabled, ) -> Self
Creates a typed writer, initializing it with the given size limit specified in bytes. Checksums are used to validate that messages arrived without corruption. The checksum will only be used if both the reader and the writer enable it. If either one disables it, then no checking is performed.
Be careful, large size limits might create a vulnerability to a Denial of Service attack.
Sourcepub fn new(raw: W, checksum_enabled: ChecksumEnabled) -> Self
pub fn new(raw: W, checksum_enabled: ChecksumEnabled) -> Self
Creates a typed writer, initializing it with a default size limit of 1 MB per message. Checksums are used to validate that messages arrived without corruption. The checksum will only be used if both the reader and the writer enable it. If either one disables it, then no checking is performed.
Sourcepub fn inner(&self) -> &W
pub fn inner(&self) -> &W
Returns a reference to the raw I/O primitive that this type is using.
Sourcepub fn into_inner(self) -> W
pub fn into_inner(self) -> W
Consumes this AsyncWriteTyped
and returns the raw I/O primitive that was being used.
Sourcepub fn optimize_memory_usage(&mut self)
pub fn optimize_memory_usage(&mut self)
AsyncWriteTyped
keeps a memory buffer for sending values which is the same size as the largest
message that’s been sent. If the message size varies a lot, you might find yourself wasting
memory space. This function will reduce the memory usage as much as is possible without impeding
functioning. Overuse of this function may cause excessive memory allocations when the buffer
needs to grow.
Sourcepub fn current_memory_usage(&self) -> usize
pub fn current_memory_usage(&self) -> usize
Reports the size of the memory buffer used for sending values. You can shrink this buffer as much as
possible with Self::optimize_memory_usage
.
Sourcepub fn checksum_enabled(&self) -> bool
pub fn checksum_enabled(&self) -> bool
Returns true if checksums are enabled for this channel. This does not guarantee that the reader is actually using those checksum values, it only reflects whether checksums are being sent.
Trait Implementations§
Source§impl<W: Debug + AsyncWrite + Unpin, T: Debug + Serialize + DeserializeOwned + Unpin> Debug for AsyncWriteTyped<W, T>
impl<W: Debug + AsyncWrite + Unpin, T: Debug + Serialize + DeserializeOwned + Unpin> Debug for AsyncWriteTyped<W, T>
Source§impl<W: AsyncWrite + Unpin, T: Serialize + DeserializeOwned + Unpin> Drop for AsyncWriteTyped<W, T>
impl<W: AsyncWrite + Unpin, T: Serialize + DeserializeOwned + Unpin> Drop for AsyncWriteTyped<W, T>
Source§impl<W: AsyncWrite + Unpin, T: Serialize + DeserializeOwned + Unpin> Sink<T> for AsyncWriteTyped<W, T>
impl<W: AsyncWrite + Unpin, T: Serialize + DeserializeOwned + Unpin> Sink<T> for AsyncWriteTyped<W, T>
Source§fn poll_ready(
self: Pin<&mut Self>,
_cx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>>
fn poll_ready( self: Pin<&mut Self>, _cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>
Sink
to receive a value. Read moreSource§fn start_send(self: Pin<&mut Self>, item: T) -> Result<(), Self::Error>
fn start_send(self: Pin<&mut Self>, item: T) -> Result<(), Self::Error>
poll_ready
which returned Poll::Ready(Ok(()))
. Read moreAuto Trait Implementations§
impl<W, T> Freeze for AsyncWriteTyped<W, T>where
W: Freeze,
impl<W, T> RefUnwindSafe for AsyncWriteTyped<W, T>where
W: RefUnwindSafe,
T: RefUnwindSafe,
impl<W, T> Send for AsyncWriteTyped<W, T>
impl<W, T> Sync for AsyncWriteTyped<W, T>
impl<W, T> Unpin for AsyncWriteTyped<W, T>
impl<W, T> UnwindSafe for AsyncWriteTyped<W, T>where
W: UnwindSafe,
T: UnwindSafe,
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, Item> SinkExt<Item> for T
impl<T, Item> SinkExt<Item> for T
Source§fn with<U, Fut, F, E>(self, f: F) -> With<Self, Item, U, Fut, F>
fn with<U, Fut, F, E>(self, f: F) -> With<Self, Item, U, Fut, F>
Source§fn with_flat_map<U, St, F>(self, f: F) -> WithFlatMap<Self, Item, U, St, F>
fn with_flat_map<U, St, F>(self, f: F) -> WithFlatMap<Self, Item, U, St, F>
Source§fn sink_map_err<E, F>(self, f: F) -> SinkMapErr<Self, F>
fn sink_map_err<E, F>(self, f: F) -> SinkMapErr<Self, F>
Source§fn sink_err_into<E>(self) -> SinkErrInto<Self, Item, E>
fn sink_err_into<E>(self) -> SinkErrInto<Self, Item, E>
Into
trait. Read moreSource§fn buffer(self, capacity: usize) -> Buffer<Self, Item>where
Self: Sized,
fn buffer(self, capacity: usize) -> Buffer<Self, Item>where
Self: Sized,
Source§fn flush(&mut self) -> Flush<'_, Self, Item>where
Self: Unpin,
fn flush(&mut self) -> Flush<'_, Self, Item>where
Self: Unpin,
Source§fn send(&mut self, item: Item) -> Send<'_, Self, Item>where
Self: Unpin,
fn send(&mut self, item: Item) -> Send<'_, Self, Item>where
Self: Unpin,
Source§fn feed(&mut self, item: Item) -> Feed<'_, Self, Item>where
Self: Unpin,
fn feed(&mut self, item: Item) -> Feed<'_, Self, Item>where
Self: Unpin,
Source§fn send_all<'a, St>(&'a mut self, stream: &'a mut St) -> SendAll<'a, Self, St>
fn send_all<'a, St>(&'a mut self, stream: &'a mut St) -> SendAll<'a, Self, St>
Source§fn right_sink<Si1>(self) -> Either<Si1, Self>
fn right_sink<Si1>(self) -> Either<Si1, Self>
Source§fn poll_ready_unpin(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>>where
Self: Unpin,
fn poll_ready_unpin(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>>where
Self: Unpin,
Sink::poll_ready
on Unpin
sink types.Source§fn start_send_unpin(&mut self, item: Item) -> Result<(), Self::Error>where
Self: Unpin,
fn start_send_unpin(&mut self, item: Item) -> Result<(), Self::Error>where
Self: Unpin,
Sink::start_send
on Unpin
sink types.