Skip to content

Commit 931b80f

Browse files
committed
Add CheckedHrpstring::fe32_iter function
Add a function that returns an iterator that yields field elements from the data part of the parsed input bech32 string.
1 parent d9b727b commit 931b80f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/primitives/decode.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,16 @@ impl<'s> CheckedHrpstring<'s> {
373373
#[inline]
374374
pub fn data_part_ascii_no_checksum(&self) -> &[u8] { self.ascii }
375375

376+
/// Returns an iterator that yields the data part of the parsed bech32 encoded string as [`Fe32`]s.
377+
///
378+
/// Converts the ASCII bytes representing field elements to the respective field elements.
379+
#[inline]
380+
pub fn fe32_iter<I: Iterator<Item = u8>>(
381+
&self,
382+
) -> AsciiToFe32Iter<iter::Copied<slice::Iter<'s, u8>>> {
383+
AsciiToFe32Iter { iter: self.ascii.iter().copied() }
384+
}
385+
376386
/// Returns an iterator that yields the data part of the parsed bech32 encoded string.
377387
///
378388
/// Converts the ASCII bytes representing field elements to the respective field elements, then
@@ -658,14 +668,14 @@ impl<'s> Iterator for Fe32Iter<'s> {
658668
fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() }
659669
}
660670

661-
/// Helper iterator adaptor that maps an iterator of valid bech32 character ASCII bytes to an
671+
/// Iterator adaptor that maps an iterator of valid bech32 character ASCII bytes to an
662672
/// iterator of field elements.
663673
///
664674
/// # Panics
665675
///
666676
/// If any `u8` in the input iterator is out of range for an [`Fe32`]. Should only be used on data
667677
/// that has already been checked for validity (eg, by using `check_characters`).
668-
struct AsciiToFe32Iter<I: Iterator<Item = u8>> {
678+
pub struct AsciiToFe32Iter<I: Iterator<Item = u8>> {
669679
iter: I,
670680
}
671681

0 commit comments

Comments
 (0)