Skip to content

Commit 4932626

Browse files
committed
Merge #118: Remove unreleased "arrayvec" code
e2eaf2d Remove unreleased arrayvec code (Tobin C. Harding) 581a913 embedded: Fix the build command doc (Tobin C. Harding) Pull request description: Modify the embedded no-allocator test to use the new `primitives` module, once that is done we can remove all the code feature gated on "arrayvec" that was recently added (and unreleased) to support allocationless encoding/decoding. ACKs for top commit: apoelstra: ACK e2eaf2d Tree-SHA512: a4548d5df178aa499b763182b9da0aa5eec05f788a2260a98996f2a3510fd17141822fd8790d7b57bd172ea6e85b4bf4914a9d921f92b976243c0f777cbcf01b
2 parents d998236 + e2eaf2d commit 4932626

File tree

5 files changed

+8
-107
lines changed

5 files changed

+8
-107
lines changed

Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,5 @@ default = ["std"]
1616
std = ["alloc"]
1717
alloc = []
1818

19-
[dependencies.arrayvec]
20-
version = "0.7.1"
21-
default-features = false
22-
optional = true
23-
2419
[target.'cfg(mutate)'.dev-dependencies]
2520
mutagen = { git = "https://github.com/llogiq/mutagen" }

contrib/test.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@ if [ "${DO_FEATURE_MATRIX-false}" = true ]; then
4848
build_and_test "std"
4949
build_and_test "alloc"
5050
build_and_test "std alloc"
51-
# arrayvec breaks the MSRV
52-
if [ $MSRV = false ]; then
53-
build_and_test "arrayvec"
54-
build_and_test "std arrayvec"
55-
build_and_test "alloc arrayvec"
56-
fi
5751
fi
5852

5953
# Build the docs if told to (this only works with the nightly toolchain)

embedded/no-allocator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ cortex-m-rt = "0.6.10"
1111
cortex-m-semihosting = "0.3.3"
1212
panic-halt = "0.2.0"
1313
arrayvec = { version = "0.7.1", default-features = false }
14-
bech32 = { path = "../../", default-features = false, features = ["arrayvec"] }
14+
bech32 = { path = "../../", default-features = false }
1515

1616
[[bin]]
1717
name = "no-allocator"

embedded/no-allocator/src/main.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
//! Test `no_std` build of `bech32`.
22
//!
3-
//! Build with: `cargo rustc -- -C link-arg=-nostartfiles`.
3+
//! Build with: `cargo +nightly rustc -- -C link-arg=-nostartfiles`.
44
//!
55
66
#![feature(alloc_error_handler)]
77
#![no_main]
88
#![no_std]
99

1010
use arrayvec::{ArrayString, ArrayVec};
11-
use bech32::{self, u5, ComboError, FromBase32, Hrp, ToBase32, Variant};
11+
use bech32::{self, u5, Hrp, Variant, ByteIterExt, Bech32};
12+
use bech32::primitives::decode::CheckedHrpstring;
1213
use cortex_m_rt::entry;
1314
use cortex_m_semihosting::{debug, hprintln};
1415
use panic_halt as _;
@@ -19,9 +20,7 @@ use panic_halt as _;
1920
fn main() -> ! {
2021
let mut encoded = ArrayString::<30>::new();
2122

22-
let mut base32 = ArrayVec::<u5, 30>::new();
23-
24-
[0x00u8, 0x01, 0x02].write_base32(&mut base32).unwrap();
23+
let base32 = [0x00u8, 0x01, 0x02].iter().copied().bytes_to_fes().collect::<ArrayVec<u5, 30>>();
2524

2625
let hrp = Hrp::parse("bech32").unwrap();
2726

@@ -30,16 +29,11 @@ fn main() -> ! {
3029

3130
hprintln!("{}", encoded).unwrap();
3231

33-
let mut decoded = ArrayVec::<u5, 30>::new();
34-
35-
let mut scratch = ArrayVec::<u5, 30>::new();
32+
let unchecked = CheckedHrpstring::new::<Bech32>(&encoded).unwrap();
3633

37-
let (got_hrp, data, variant) =
38-
bech32::decode_lowercase::<ComboError, _, _>(&encoded, &mut decoded, &mut scratch).unwrap();
39-
test(got_hrp == hrp);
40-
let res = ArrayVec::<u8, 30>::from_base32(&data).unwrap();
34+
test(unchecked.hrp() == hrp);
35+
let res = unchecked.byte_iter().collect::<ArrayVec<u8, 30>>();
4136
test(&res == [0x00, 0x01, 0x02].as_ref());
42-
test(variant == Variant::Bech32);
4337

4438
debug::exit(debug::EXIT_SUCCESS);
4539

src/lib.rs

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ pub use crate::primitives::{Bech32, Bech32m};
4444
mod error;
4545
pub mod primitives;
4646

47-
#[cfg(feature = "arrayvec")]
48-
use arrayvec::{ArrayVec, CapacityError};
4947
pub use primitives::gf32::Fe32 as u5;
5048

5149
/// Interface to write `u5`s into a sink.
@@ -164,21 +162,6 @@ pub trait FromBase32: Sized {
164162

165163
macro_rules! write_base_n {
166164
{ $tr:ident, $ty:ident, $meth:ident } => {
167-
#[cfg(feature = "arrayvec")]
168-
impl<const L: usize> $tr for ArrayVec<$ty, L> {
169-
type Error = CapacityError;
170-
171-
fn write(&mut self, data: &[$ty]) -> Result<(), Self::Error> {
172-
self.try_extend_from_slice(data)?;
173-
Ok(())
174-
}
175-
176-
fn $meth(&mut self, data: $ty) -> Result<(), Self::Error> {
177-
self.push(data);
178-
Ok(())
179-
}
180-
}
181-
182165
#[cfg(feature = "alloc")]
183166
impl $tr for Vec<$ty> {
184167
type Error = Infallible;
@@ -199,41 +182,6 @@ macro_rules! write_base_n {
199182
write_base_n! { WriteBase32, u5, write_u5 }
200183
write_base_n! { WriteBase256, u8, write_u8 }
201184

202-
#[cfg(feature = "arrayvec")]
203-
#[derive(Clone, Debug, PartialEq, Eq)]
204-
/// Combination of Errors for use with array vec
205-
pub enum ComboError {
206-
/// Error from this crate
207-
Bech32Error(Error),
208-
/// Error from `arrayvec`.
209-
WriteError(CapacityError),
210-
}
211-
#[cfg(feature = "arrayvec")]
212-
impl From<Error> for ComboError {
213-
fn from(e: Error) -> ComboError { ComboError::Bech32Error(e) }
214-
}
215-
#[cfg(feature = "arrayvec")]
216-
impl From<CapacityError> for ComboError {
217-
fn from(e: CapacityError) -> ComboError { ComboError::WriteError(e) }
218-
}
219-
#[cfg(feature = "arrayvec")]
220-
impl From<hrp::Error> for ComboError {
221-
fn from(e: hrp::Error) -> ComboError { ComboError::Bech32Error(Error::Hrp(e)) }
222-
}
223-
224-
#[cfg(feature = "arrayvec")]
225-
impl<const L: usize> FromBase32 for ArrayVec<u8, L> {
226-
type Error = ComboError;
227-
228-
/// Convert base32 to base256, removes null-padding if present, returns
229-
/// `Err(Error::InvalidPadding)` if padding bits are unequal `0`
230-
fn from_base32(b32: &[u5]) -> Result<Self, Self::Error> {
231-
let mut ret: ArrayVec<u8, L> = ArrayVec::new();
232-
convert_bits_in::<ComboError, _, _>(b32, 5, 8, false, &mut ret)?;
233-
Ok(ret)
234-
}
235-
}
236-
237185
#[cfg(feature = "alloc")]
238186
impl FromBase32 for Vec<u8> {
239187
type Error = Error;
@@ -861,9 +809,6 @@ where
861809

862810
#[cfg(test)]
863811
mod tests {
864-
#[cfg(feature = "arrayvec")]
865-
use arrayvec::ArrayString;
866-
867812
use super::*;
868813

869814
#[cfg(feature = "alloc")]
@@ -1164,33 +1109,6 @@ mod tests {
11641109
assert!(u5::try_from(32_u128).is_err());
11651110
}
11661111

1167-
#[test]
1168-
#[cfg(feature = "arrayvec")]
1169-
fn test_arrayvec() {
1170-
let mut encoded = ArrayString::<30>::new();
1171-
1172-
let mut base32 = ArrayVec::<u5, 30>::new();
1173-
1174-
[0x00u8, 0x01, 0x02].write_base32(&mut base32).unwrap();
1175-
1176-
let bech32_hrp = Hrp::parse("bech32").expect("bech32 is valid");
1177-
encode_to_fmt_anycase(&mut encoded, bech32_hrp, &base32, Variant::Bech32).unwrap().unwrap();
1178-
assert_eq!(&*encoded, "bech321qqqsyrhqy2a");
1179-
1180-
println!("{}", encoded);
1181-
1182-
let mut decoded = ArrayVec::<u5, 30>::new();
1183-
1184-
let mut scratch = ArrayVec::<u5, 30>::new();
1185-
1186-
let (hrp, data, variant) =
1187-
decode_lowercase::<ComboError, _, _>(&encoded, &mut decoded, &mut scratch).unwrap();
1188-
assert_eq!(hrp.to_string(), "bech32");
1189-
let res = ArrayVec::<u8, 30>::from_base32(data).unwrap();
1190-
assert_eq!(&res, [0x00, 0x01, 0x02].as_ref());
1191-
assert_eq!(variant, Variant::Bech32);
1192-
}
1193-
11941112
#[test]
11951113
#[cfg(feature = "alloc")]
11961114
fn decode_bitcoin_bech32_address() {

0 commit comments

Comments
 (0)