bdk_chain::bitcoin::hashes::hex::buf_encoder

Struct BufEncoder

pub struct BufEncoder<const CAP: usize> { /* 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§

§

impl<const CAP: usize> BufEncoder<CAP>

pub fn new() -> BufEncoder<CAP>

Creates an empty BufEncoder.

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.

pub fn put_bytes<I>(&mut self, bytes: I, case: Case)
where I: IntoIterator, <I as IntoIterator>::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.

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

pub fn is_full(&self) -> bool

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

pub fn as_str(&self) -> &str

Returns the written bytes as a hex str.

pub fn clear(&mut self)

Resets the buffer to become empty.

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.

Trait Implementations§

§

impl<const CAP: usize> Default for BufEncoder<CAP>

§

fn default() -> BufEncoder<CAP>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<const CAP: usize> Freeze for BufEncoder<CAP>

§

impl<const CAP: usize> RefUnwindSafe for BufEncoder<CAP>

§

impl<const CAP: usize> Send for BufEncoder<CAP>

§

impl<const CAP: usize> Sync for BufEncoder<CAP>

§

impl<const CAP: usize> Unpin for BufEncoder<CAP>

§

impl<const CAP: usize> UnwindSafe for BufEncoder<CAP>

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V