pub struct Encoder<'hrp, I, Ck>
where I: Iterator<Item = Fe32>, Ck: Checksum,
{ /* private fields */ }
Expand description

The Encoder builds iterators that can be used to encode field elements into a bech32 address.

Construct the encoder by calling Fe32IterExt::with_checksum on an iterator of field elements, optionally prefix the data with a witness version, and then get the encoding as either a stream of characters (Encoder::chars) or a stream of field elements (Encoder::fes).

§Examples

use bech32::{Bech32, ByteIterExt, Fe32IterExt, Hrp};

let data = [0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4];

let hrp = Hrp::parse("abc").expect("bc is valid hrp string");
let chars = data
    .iter()
    .copied()
    .bytes_to_fes()
    .with_checksum::<Bech32>(&hrp)
    .chars();

Implementations§

source§

impl<'hrp, I, Ck> Encoder<'hrp, I, Ck>
where I: Iterator<Item = Fe32>, Ck: Checksum,

source

pub fn new(data: I, hrp: &'hrp Hrp) -> Self

Constructs a new bech32 encoder.

source

pub fn with_witness_version(self, witness_version: Fe32) -> Self

Adds witness_version to the encoder (as first byte of encoded data).

Note, caller to guarantee that witness version is within valid range (0-16).

source

pub fn chars(self) -> CharIter<'hrp, I, Ck>

Returns an iterator that yields the bech32 encoded address as field ASCII characters.

source

pub fn bytes(self) -> ByteIter<'hrp, I, Ck>

Returns an iterator that yields the bech32 encoded address as field ASCII characters, as byte values.

source

pub fn fes(self) -> Fe32Iter<'hrp, I, Ck>

Returns an iterator that yields the field elements that go into the checksum, as well as the checksum at the end.

Each field element yielded has been input into the checksum algorithm (including the HRP as it is fed into the algorithm).

Trait Implementations§

source§

impl<'hrp, I, Ck> Clone for Encoder<'hrp, I, Ck>
where I: Iterator<Item = Fe32> + Clone, Ck: Checksum + Clone,

source§

fn clone(&self) -> Encoder<'hrp, I, Ck>

Returns a copy 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<'hrp, I, Ck> PartialEq for Encoder<'hrp, I, Ck>
where I: Iterator<Item = Fe32> + PartialEq, Ck: Checksum + PartialEq,

source§

fn eq(&self, other: &Encoder<'hrp, I, Ck>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'hrp, I, Ck> Eq for Encoder<'hrp, I, Ck>
where I: Iterator<Item = Fe32> + Eq, Ck: Checksum + Eq,

source§

impl<'hrp, I, Ck> StructuralPartialEq for Encoder<'hrp, I, Ck>
where I: Iterator<Item = Fe32>, Ck: Checksum,

Auto Trait Implementations§

§

impl<'hrp, I, Ck> RefUnwindSafe for Encoder<'hrp, I, Ck>

§

impl<'hrp, I, Ck> Send for Encoder<'hrp, I, Ck>
where Ck: Send, I: Send,

§

impl<'hrp, I, Ck> Sync for Encoder<'hrp, I, Ck>
where Ck: Sync, I: Sync,

§

impl<'hrp, I, Ck> Unpin for Encoder<'hrp, I, Ck>
where Ck: Unpin, I: Unpin,

§

impl<'hrp, I, Ck> UnwindSafe for Encoder<'hrp, I, Ck>
where Ck: UnwindSafe, I: 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> ToOwned for T
where T: Clone,

§

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

§

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.