Struct data_encoding::Encoder

source ·
pub struct Encoder<'a> { /* private fields */ }
Available on crate feature alloc only.
Expand description

Encodes fragmented input to an output

It is equivalent to use an Encoder with multiple calls to Encoder::append() than to first concatenate all the input and then use Encoding::encode_append(). In particular, this function will not introduce padding or wrapping between inputs.

§Examples

// This is a bit inconvenient but we can't take a long-term reference to data_encoding::BASE64
// because it's a constant. We need to use a static which has an address instead. This will be
// fixed in version 3 of the library.
static BASE64: data_encoding::Encoding = data_encoding::BASE64;
let mut output = String::new();
let mut encoder = BASE64.new_encoder(&mut output);
encoder.append(b"hello");
encoder.append(b"world");
encoder.finalize();
assert_eq!(output, BASE64.encode(b"helloworld"));

Implementations§

source§

impl<'a> Encoder<'a>

source

pub fn append(&mut self, input: &[u8])

Encodes the provided input fragment and appends the result to the output

source

pub fn finalize(self)

Makes sure all inputs have been encoded and appended to the output

This is equivalent to dropping the encoder and required for correctness, otherwise some encoded data may be missing at the end.

Trait Implementations§

source§

impl<'a> Debug for Encoder<'a>

source§

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

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

impl<'a> Drop for Encoder<'a>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Encoder<'a>

§

impl<'a> RefUnwindSafe for Encoder<'a>

§

impl<'a> Send for Encoder<'a>

§

impl<'a> Sync for Encoder<'a>

§

impl<'a> Unpin for Encoder<'a>

§

impl<'a> !UnwindSafe for Encoder<'a>

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

§

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

§

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.