pub struct BufEncoder<T: AsOutBytes> { /* private fields */ }
Expand description

Hex-encodes bytes into the provided buffer.

This is an important building block for fast hex-encoding. Because string writing tools provided by core::fmt involve dynamic dispatch and don’t allow reserving capacity in strings buffering the hex and then formatting it is significantly faster.

Implementations§

source§

impl<T: AsOutBytes> BufEncoder<T>

source

pub fn new(buf: T) -> Self

Creates an empty BufEncoder.

This is usually used with uninitialized (zeroed) byte array allocated on stack. This can only be constructed with an even-length, non-empty array.

source

pub fn put_byte(&mut self, byte: u8, case: Case)

Encodes byte as hex in given case and appends it to the buffer.

Panics

The method panics if the buffer is full.

source

pub fn put_bytes<I>(&mut self, bytes: I, case: Case)where I: IntoIterator, I::Item: Borrow<u8>,

Encodes bytes as hex in given case and appends them to the buffer.

Panics

The method panics if the bytes wouldn’t fit the buffer.

source

pub fn put_bytes_min<'a>(&mut self, bytes: &'a [u8], case: Case) -> &'a [u8]

Encodes as many bytes as fit into the buffer as hex and return the remainder.

This method works just like put_bytes but instead of panicking it returns the unwritten bytes. The method returns an empty slice if all bytes were written

source

pub fn is_full(&self) -> bool

Returns true if no more bytes can be written into the buffer.

source

pub fn as_str(&self) -> &str

Returns the written bytes as a hex str.

source

pub fn clear(&mut self)

Resets the buffer to become empty.

source

pub fn space_remaining(&self) -> usize

How many bytes can be written to this buffer.

Note that this returns the number of bytes before encoding, not number of hex digits.

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for BufEncoder<T>where T: RefUnwindSafe,

§

impl<T> Send for BufEncoder<T>where T: Send,

§

impl<T> Sync for BufEncoder<T>where T: Sync,

§

impl<T> Unpin for BufEncoder<T>where T: Unpin,

§

impl<T> UnwindSafe for BufEncoder<T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.