pub struct EncoderPositionTracker<Enc> { /* private fields */ }Expand description
An Encoder wrapper that handles partial writes.
This wrapper internally tracks the position of encoded bytes which makes handling of partial writes very easy. It also simplifies handling of the end.
Implementations§
Source§impl<Enc: Encoder> EncoderPositionTracker<Enc>
impl<Enc: Encoder> EncoderPositionTracker<Enc>
Sourcepub fn encoded_chunk(&self) -> &[u8] ⓘ
pub fn encoded_chunk(&self) -> &[u8] ⓘ
Returns an unprocessed chunk of encoded data.
The returned bytes should be processed - e.g. by writing them into a writer. Empty returned value indicates there are no more bytes.
Sourcepub fn consume(&mut self, amount: usize)
pub fn consume(&mut self, amount: usize)
Marks the amount of bytes as processed.
The consumer should call this method after (partially) processing the chunk. Usually this
is called after successful write or analogous function. The
buffer returned by encoded_chunk will by advanced by amount
bytes and, if it reached the end, the underlying encoder will be advanced to give the next
chunk.
Calling this method with amount larger than encoded_chunk().len() will corrupt the
encoder and lead to a panic later. In debug builds this will panic instantly.
Sourcepub fn write_once<W: Write>(&mut self, writer: &mut W) -> Result<usize>
Available on crate feature std only.
pub fn write_once<W: Write>(&mut self, writer: &mut W) -> Result<usize>
std only.Issues single write to te writer and advances the position accordingly.
This can be used as a building block for various abstractions or protocols. Returns the number of bytes written. Zero indicates the end of encoding.
Sourcepub fn write_all<W: Write>(&mut self, writer: &mut W) -> Result<()>
Available on crate feature std only.
pub fn write_all<W: Write>(&mut self, writer: &mut W) -> Result<()>
std only.Writes all bytes to the writer until the end or an error.
This is similar to Encoder::write_all with one significant difference: it leaves the
state around so the operation can be restarted. This can be used to handle
ErrorKind::Interrupted errors which are generally
recoverable but users may still wish to act on them (e.g. check a global flag set by a
signal).
Trait Implementations§
Source§impl<Enc: Clone> Clone for EncoderPositionTracker<Enc>
impl<Enc: Clone> Clone for EncoderPositionTracker<Enc>
Source§fn clone(&self) -> EncoderPositionTracker<Enc>
fn clone(&self) -> EncoderPositionTracker<Enc>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<Enc> Freeze for EncoderPositionTracker<Enc>where
Enc: Freeze,
impl<Enc> RefUnwindSafe for EncoderPositionTracker<Enc>where
Enc: RefUnwindSafe,
impl<Enc> Send for EncoderPositionTracker<Enc>where
Enc: Send,
impl<Enc> Sync for EncoderPositionTracker<Enc>where
Enc: Sync,
impl<Enc> Unpin for EncoderPositionTracker<Enc>where
Enc: Unpin,
impl<Enc> UnwindSafe for EncoderPositionTracker<Enc>where
Enc: 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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more