Struct bech32::primitives::encode::Encoder
source · 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§
source§impl<'hrp, I, Ck> Encoder<'hrp, I, Ck>
impl<'hrp, I, Ck> Encoder<'hrp, I, Ck>
sourcepub fn with_witness_version(self, witness_version: Fe32) -> Self
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).
sourcepub 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§
source§impl<'hrp, I, Ck> PartialEq for Encoder<'hrp, I, Ck>
impl<'hrp, I, Ck> PartialEq for Encoder<'hrp, I, Ck>
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> RefUnwindSafe for Encoder<'hrp, I, Ck>where
Ck: RefUnwindSafe,
I: 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
Ck: UnwindSafe,
I: 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