Skip to content

Commit d244386

Browse files
committed
Use string not address in lib.rs
The `crate::{encode, decode}` API is for encoding/decoding bech32 strings not specifically addresses (for example miniscript descriptors are bech32 strings but not addresses). Use the words "bech32 string" instead of "address" in `lib.rs`.
1 parent 254202e commit d244386

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/lib.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@
3838
//! use bech32::{hrp, segwit, Hrp, Bech32m};
3939
//!
4040
//! const DATA: [u8; 20] = [0xab; 20]; // Arbitrary data to be encoded.
41-
//! const ADDR: &str = "abc14w46h2at4w46h2at4w46h2at4w46h2at958ngu";
41+
//! const STRING: &str = "abc14w46h2at4w46h2at4w46h2at4w46h2at958ngu";
4242
//! const TAP_ADDR: &str = "bc1p4w46h2at4w46h2at4w46h2at4w46h2at5kreae";
4343
//!
4444
//! // Encode arbitrary data using "abc" as the human-readable part and append a bech32m checksum.
4545
//! let hrp = Hrp::parse("abc").expect("valid hrp");
46-
//! let address = bech32::encode::<Bech32m>(hrp, &DATA).expect("failed to encode address");
47-
//! assert_eq!(address, ADDR);
46+
//! let string = bech32::encode::<Bech32m>(hrp, &DATA).expect("failed to encode string");
47+
//! assert_eq!(string, STRING);
4848
//!
4949
//! // Encode arbitrary data as a Bitcoin taproot address.
5050
//! let taproot_address = segwit::encode(hrp::BC, segwit::VERSION_1, &DATA).expect("valid witness version and program");
@@ -53,7 +53,7 @@
5353
//! // No-alloc: Encode without allocating (ignoring that String::new() allocates :).
5454
//! let mut buf = String::new();
5555
//! bech32::encode_to_fmt::<Bech32m, String>(&mut buf, hrp, &DATA).expect("failed to encode to buffer");
56-
//! assert_eq!(buf, ADDR);
56+
//! assert_eq!(buf, STRING);
5757
//! # }
5858
//! ```
5959
//!
@@ -65,15 +65,15 @@
6565
//! use bech32::{hrp, segwit, Hrp, Bech32m};
6666
//!
6767
//! const DATA: [u8; 20] = [0xab; 20]; // Arbitrary data to be encoded.
68-
//! const ADDR: &str = "abc14w46h2at4w46h2at4w46h2at4w46h2at958ngu";
68+
//! const STRING: &str = "abc14w46h2at4w46h2at4w46h2at4w46h2at958ngu";
6969
//! const TAP_ADDR: &str = "bc1p4w46h2at4w46h2at4w46h2at4w46h2at5kreae";
7070
//!
7171
//! // Decode a bech32 encoded string that includes a bech32/bech32m checksum.
7272
//! //
7373
//! // The input address MUST include a valid bech32 or bech32m checksum, for individual specific
7474
//! // checksum algorithms see [`decode_bech32`], [`decode_bech32m`], [`decode_no_checksum`] or use
7575
//! // the [`primitives::decode::CheckedHrpstring`] type directly.
76-
//! let (hrp, data) = bech32::decode(&ADDR).expect("failed to decode");
76+
//! let (hrp, data) = bech32::decode(&STRING).expect("failed to decode");
7777
//! assert_eq!(hrp, Hrp::parse("abc").unwrap());
7878
//! assert_eq!(data, DATA);
7979
//!
@@ -82,7 +82,7 @@
8282
//! assert_eq!(program, DATA);
8383
//!
8484
//! // No-alloc: Decode a bech32m checksummed address without allocating.
85-
//! let p = CheckedHrpstring::new::<Bech32m>(&ADDR).expect("failed to parse address");
85+
//! let p = CheckedHrpstring::new::<Bech32m>(&STRING).expect("failed to parse string");
8686
//! assert_eq!(hrp, p.hrp());
8787
//! assert!(p.byte_iter().eq(DATA.iter().map(|&b| b))); // We yield bytes not references.
8888
//!
@@ -197,14 +197,14 @@ pub use {
197197
/// const BECH32M: &str = "abc14w46h2at4w46h2at4w46h2at4w46h2at958ngu";
198198
/// const NO_CHECKSUM: &str = "abc14w46h2at4w46h2at4w46h2at4w46h2at";
199199
///
200-
/// let (hrp, data) = decode(&BECH32).expect("valid address with valid bech32 checksum");
201-
/// let (hrp, data) = decode(&BECH32M).expect("valid address with valid bech32m checksum");
200+
/// let (hrp, data) = decode(&BECH32).expect("valid bech32 string with valid bech32 checksum");
201+
/// let (hrp, data) = decode(&BECH32M).expect("valid bech32 string with valid bech32m checksum");
202202
/// assert!(decode(&NO_CHECKSUM).is_err());
203203
///
204204
/// // You can control the checksum algorithm directly by using the [`CheckedHrpstring`] type.
205-
/// let p = CheckedHrpstring::new::<Bech32>(&BECH32).expect("valid address with valid bech32 checksum");
206-
/// let p = CheckedHrpstring::new::<Bech32m>(&BECH32M).expect("valid address with valid bech32 checksum");
207-
/// let p = CheckedHrpstring::new::<NoChecksum>(&NO_CHECKSUM).expect("valid address with no checksum");
205+
/// let p = CheckedHrpstring::new::<Bech32>(&BECH32).expect("valid bech32 string with valid bech32 checksum");
206+
/// let p = CheckedHrpstring::new::<Bech32m>(&BECH32M).expect("valid bech32 string with valid bech32 checksum");
207+
/// let p = CheckedHrpstring::new::<NoChecksum>(&NO_CHECKSUM).expect("valid bech32 string with no checksum");
208208
/// # }
209209
/// ```
210210
#[cfg(feature = "alloc")]
@@ -406,7 +406,7 @@ pub fn encoded_length<Ck: Checksum>(hrp: Hrp, data: &[u8]) -> usize {
406406
hrp.len() + 1 + iter.len() + Ck::CHECKSUM_LENGTH // +1 for separator
407407
}
408408

409-
/// An error while decoding an address.
409+
/// An error while decoding a bech32 string.
410410
#[cfg(feature = "alloc")]
411411
#[derive(Debug, Clone, PartialEq, Eq)]
412412
#[non_exhaustive]
@@ -622,7 +622,7 @@ mod tests {
622622
#[test]
623623
fn encoded_length_works() {
624624
let s = "test1lu08d6qejxtdg4y5r3zarvary0c5xw7kmz4lky";
625-
let (hrp, data) = decode(s).expect("failed to decode valid address");
625+
let (hrp, data) = decode(s).expect("failed to decode valid bech32 string");
626626

627627
let encoded = encode::<Bech32m>(hrp, &data).expect("failed to encode string");
628628
let want = encoded.len();

0 commit comments

Comments
 (0)