Struct EncoderPositionTracker

Source
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>

Source

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.

Source

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.

Source

pub fn write_once<W: Write>(&mut self, writer: &mut W) -> Result<usize>

Available on crate feature 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.

Source

pub fn write_all<W: Write>(&mut self, writer: &mut W) -> Result<()>

Available on crate feature 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>

Source§

fn clone(&self) -> EncoderPositionTracker<Enc>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Enc: Debug> Debug for EncoderPositionTracker<Enc>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.