Struct Encoder
pub struct Encoder<'hrp, I, Ck>{ /* 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§
§impl<'hrp, I, Ck> Encoder<'hrp, I, Ck>
impl<'hrp, I, Ck> Encoder<'hrp, I, Ck>
pub fn with_witness_version(self, witness_version: Fe32) -> Encoder<'hrp, I, Ck>
pub fn with_witness_version(self, witness_version: Fe32) -> Encoder<'hrp, I, Ck>
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).
pub fn chars(self) -> CharIter<'hrp, I, Ck> ⓘ
pub fn chars(self) -> CharIter<'hrp, I, Ck> ⓘ
Returns an iterator that yields the bech32 encoded address as field ASCII characters.
Trait Implementations§
impl<'hrp, I, Ck> Eq for Encoder<'hrp, I, Ck>
impl<'hrp, I, Ck> StructuralPartialEq for Encoder<'hrp, I, Ck>
Auto Trait Implementations§
impl<'hrp, I, Ck> Freeze for Encoder<'hrp, I, Ck>where
I: Freeze,
impl<'hrp, I, Ck> RefUnwindSafe for Encoder<'hrp, I, Ck>where
I: RefUnwindSafe,
Ck: RefUnwindSafe,
impl<'hrp, I, Ck> Send for Encoder<'hrp, I, Ck>
impl<'hrp, I, Ck> Sync for Encoder<'hrp, I, Ck>
impl<'hrp, I, Ck> Unpin for Encoder<'hrp, I, Ck>
impl<'hrp, I, Ck> UnwindSafe for Encoder<'hrp, I, Ck>where
I: UnwindSafe,
Ck: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more