Skip to main content

Encoder

Struct Encoder 

Source
pub struct Encoder<W, A, const PAD: bool>
where A: Alphabet,
{ /* private fields */ }
Expand description

A streaming Base64 encoder for std::io::Write.

Like any Write implementation, Write::write may accept only part of the provided input. Accepted input may be held as encoded output until Write::flush, Self::try_finish, Self::finish, or a later write drains the wrapped writer. Use Write::write_all when the whole input slice must be consumed.

Implementations§

Source§

impl<W, A, const PAD: bool> Encoder<W, A, PAD>
where A: Alphabet,

Source

pub const fn new(inner: W, engine: Engine<A, PAD>) -> Self

Creates a new streaming encoder.

Source

pub fn get_ref(&self) -> &W

Returns a shared reference to the wrapped writer.

Source

pub fn get_mut(&mut self) -> &mut W

Returns a mutable reference to the wrapped writer.

Source

pub const fn engine(&self) -> Engine<A, PAD>

Returns the Base64 engine used by this adapter.

Source

pub const fn is_padded(&self) -> bool

Returns whether this adapter uses padded Base64.

Source

pub const fn pending_len(&self) -> usize

Returns the number of raw input bytes currently buffered until a complete 3-byte Base64 encode quantum is available.

Source

pub const fn has_pending_input(&self) -> bool

Returns whether this encoder currently holds a partial input quantum.

Source

pub const fn pending_input_needed_len(&self) -> usize

Returns how many additional input bytes are needed to complete the currently buffered encode quantum.

Returns 0 when no partial input quantum is buffered.

Source

pub const fn buffered_output_len(&self) -> usize

Returns the number of encoded bytes buffered for the wrapped writer after a previous write or flush could not fully drain them.

Source

pub const fn buffered_output_capacity(&self) -> usize

Returns the maximum number of encoded bytes this adapter can buffer before returning bytes to the caller.

Source

pub const fn buffered_output_remaining_capacity(&self) -> usize

Returns how many more encoded bytes can be buffered before this adapter must drain the wrapped writer.

Source

pub const fn has_buffered_output(&self) -> bool

Returns whether this encoder has encoded output waiting to be written to the wrapped writer.

Source

pub const fn is_finalized(&self) -> bool

Returns whether this encoder has been finalized.

Once this returns true, later non-empty writes return an error.

Source

pub const fn can_into_inner(&self) -> bool

Returns whether Self::try_into_inner can recover the wrapped writer without discarding pending input.

Source

pub fn into_inner(self) -> W

Consumes the encoder without flushing pending input.

Prefer Self::finish when the encoded output must be complete.

Source

pub fn try_into_inner(self) -> Result<W, Self>

Consumes the encoder only when no partial input quantum is buffered.

This does not flush or finalize the wrapped writer. It is a checked alternative to Self::into_inner for callers that want to avoid accidentally discarding pending input bytes.

Source§

impl<W, A, const PAD: bool> Encoder<W, A, PAD>
where W: Write, A: Alphabet,

Source

pub fn try_finish(&mut self) -> Result<()>

Writes any pending input and flushes the wrapped writer without consuming this encoder.

After this succeeds, Self::pending_len returns 0, later writes are rejected, and Self::finish can still be used to recover the wrapped writer. This is useful when a caller needs to finalize a framed payload while keeping the stream adapter available for diagnostics or explicit recovery.

Source

pub fn finish(self) -> Result<W>

Writes any pending input, flushes the wrapped writer, and returns it.

Trait Implementations§

Source§

impl<W, A, const PAD: bool> Debug for Encoder<W, A, PAD>
where A: Alphabet,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<W, A, const PAD: bool> Drop for Encoder<W, A, PAD>
where A: Alphabet,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<W, A, const PAD: bool> Write for Encoder<W, A, PAD>
where W: Write, A: Alphabet,

Source§

fn write(&mut self, input: &[u8]) -> Result<usize>

Writes a buffer into this writer, returning how many bytes were written. Read more
Source§

fn flush(&mut self) -> Result<()>

Flushes this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
1.36.0 · Source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>

Like write, except that it writes from a slice of buffers. Read more
Source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
1.0.0 · Source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>

Attempts to write an entire buffer into this writer. Read more
Source§

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
1.0.0 · Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Writes a formatted string into this writer, returning any error encountered. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Write. Read more

Auto Trait Implementations§

§

impl<W, A, const PAD: bool> Freeze for Encoder<W, A, PAD>
where W: Freeze,

§

impl<W, A, const PAD: bool> RefUnwindSafe for Encoder<W, A, PAD>

§

impl<W, A, const PAD: bool> Send for Encoder<W, A, PAD>
where W: Send, A: Send,

§

impl<W, A, const PAD: bool> Sync for Encoder<W, A, PAD>
where W: Sync, A: Sync,

§

impl<W, A, const PAD: bool> Unpin for Encoder<W, A, PAD>
where W: Unpin, A: Unpin,

§

impl<W, A, const PAD: bool> UnsafeUnpin for Encoder<W, A, PAD>
where W: UnsafeUnpin,

§

impl<W, A, const PAD: bool> UnwindSafe for Encoder<W, A, PAD>
where W: UnwindSafe, A: 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> 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, 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.