Skip to content

Commit

Permalink
Deal with deprecation of IntoIter::new.
Browse files Browse the repository at this point in the history
  • Loading branch information
briansmith committed Apr 8, 2022
1 parent 431069e commit fe12e51
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/limb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
//! Limbs ordered least-significant-limb to most-significant-limb. The bits
//! limbs use the native endianness.
use crate::{c, error, polyfill::ArrayFlatMap};
use crate::{
c, error,
polyfill::{self, ArrayFlatMap},
};

#[cfg(any(test, feature = "alloc"))]
use crate::bits;
Expand Down Expand Up @@ -251,7 +254,7 @@ pub fn big_endian_from_limbs(limbs: &[Limb], out: &mut [u8]) {
pub fn unstripped_be_bytes(limbs: &[Limb]) -> impl ExactSizeIterator<Item = u8> + Clone + '_ {
// The unwrap is safe because a slice can never be larger than `usize` bytes.
ArrayFlatMap::new(limbs.iter().rev().copied(), |limb| {
core::array::IntoIter::new(Limb::to_be_bytes(limb))
polyfill::array::into_iter(Limb::to_be_bytes(limb))
})
.unwrap()
}
Expand Down
2 changes: 2 additions & 0 deletions src/polyfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub fn usize_from_u32(x: u32) -> usize {
#[macro_use]
mod chunks_fixed;

pub(crate) mod array;

mod array_flat_map;
pub(crate) mod array_map;

Expand Down
20 changes: 20 additions & 0 deletions src/polyfill/array.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2022 Brian Smith.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

// TODO: Remove this and use `IntoIterator::into_ter` once MSRV is 1.59.0 or later.
#[inline(always)]
pub(crate) fn into_iter<T, const N: usize>(array: [T; N]) -> core::array::IntoIter<T, N> {
#[allow(deprecated)]
core::array::IntoIter::new(array)
}
5 changes: 3 additions & 2 deletions src/polyfill/array_flat_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ where
#[cfg(test)]
mod tests {
use super::*;
use crate::polyfill;

#[test]
fn test_array_flat_map() {
Expand All @@ -81,7 +82,7 @@ mod tests {
];
TEST_CASES.iter().copied().for_each(|(input, f, expected)| {
let mapped = ArrayFlatMap::new(input.iter().copied(), |input| {
core::array::IntoIter::new(f(input))
polyfill::array::into_iter(f(input))
})
.unwrap();
super::super::test::assert_iterator(mapped, expected);
Expand Down Expand Up @@ -121,7 +122,7 @@ mod tests {
remaining: input_len,
};
let mapped = ArrayFlatMap::new(inner, |input| {
core::array::IntoIter::new(usize::to_be_bytes(input))
polyfill::array::into_iter(usize::to_be_bytes(input))
});
assert_eq!(mapped.is_some(), is_some);
if let Some(mapped) = mapped {
Expand Down
4 changes: 2 additions & 2 deletions src/rsa/public_exponent.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::error;
use crate::polyfill::{ArrayFlatMap, LeadingZerosStripped};
use crate::polyfill::{self, ArrayFlatMap, LeadingZerosStripped};
use core::num::NonZeroU64;

/// The exponent `e` of an RSA public key.
Expand Down Expand Up @@ -85,7 +85,7 @@ impl PublicExponent {
pub fn be_bytes(&self) -> impl ExactSizeIterator<Item = u8> + Clone + '_ {
// The `unwrap()` won't fail as `self.0` is only a few bytes long.
let bytes = ArrayFlatMap::new(core::iter::once(self.0.get()), |value| {
core::array::IntoIter::new(u64::to_be_bytes(value))
polyfill::array::into_iter(u64::to_be_bytes(value))
})
.unwrap();
LeadingZerosStripped::new(bytes)
Expand Down

0 comments on commit fe12e51

Please sign in to comment.