Skip to content

Commit

Permalink
Remove generics from AsciiToFe32Iter
Browse files Browse the repository at this point in the history
The `AsciiToFe32Iter` always iterates over the input string, we can just
use the lifetime from the string and a `iter::Copied<slice::Iter<'s,
u8>` iterator.
  • Loading branch information
tcharding committed Jan 23, 2024
1 parent 931b80f commit 319d9e3
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/primitives/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,7 @@ impl<'s> CheckedHrpstring<'s> {
///
/// Converts the ASCII bytes representing field elements to the respective field elements.
#[inline]
pub fn fe32_iter<I: Iterator<Item = u8>>(
&self,
) -> AsciiToFe32Iter<iter::Copied<slice::Iter<'s, u8>>> {
pub fn fe32_iter<I: Iterator<Item = u8>>(&self) -> AsciiToFe32Iter {
AsciiToFe32Iter { iter: self.ascii.iter().copied() }
}

Expand Down Expand Up @@ -639,7 +637,7 @@ fn check_characters(s: &str) -> Result<usize, CharError> {

/// An iterator over a parsed HRP string data as bytes.
pub struct ByteIter<'s> {
iter: FesToBytes<AsciiToFe32Iter<iter::Copied<slice::Iter<'s, u8>>>>,
iter: FesToBytes<AsciiToFe32Iter<'s>>,
}

impl<'s> Iterator for ByteIter<'s> {
Expand All @@ -657,7 +655,7 @@ impl<'s> ExactSizeIterator for ByteIter<'s> {

/// An iterator over a parsed HRP string data as field elements.
pub struct Fe32Iter<'s> {
iter: AsciiToFe32Iter<iter::Copied<slice::Iter<'s, u8>>>,
iter: AsciiToFe32Iter<'s>,
}

impl<'s> Iterator for Fe32Iter<'s> {
Expand All @@ -675,14 +673,11 @@ impl<'s> Iterator for Fe32Iter<'s> {
///
/// If any `u8` in the input iterator is out of range for an [`Fe32`]. Should only be used on data
/// that has already been checked for validity (eg, by using `check_characters`).
pub struct AsciiToFe32Iter<I: Iterator<Item = u8>> {
iter: I,
pub struct AsciiToFe32Iter<'s> {
iter: iter::Copied<slice::Iter<'s, u8>>,
}

impl<I> Iterator for AsciiToFe32Iter<I>
where
I: Iterator<Item = u8>,
{
impl<'s> Iterator for AsciiToFe32Iter<'s> {
type Item = Fe32;
#[inline]
fn next(&mut self) -> Option<Fe32> { self.iter.next().map(Fe32::from_char_unchecked) }
Expand All @@ -693,10 +688,7 @@ where
}
}

impl<I> ExactSizeIterator for AsciiToFe32Iter<I>
where
I: Iterator<Item = u8> + ExactSizeIterator,
{
impl<'s> ExactSizeIterator for AsciiToFe32Iter<'s> {
#[inline]
fn len(&self) -> usize { self.iter.len() }
}
Expand Down

0 comments on commit 319d9e3

Please sign in to comment.