Skip to content

Commit 48d7eb6

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 b0677c8 commit 48d7eb6

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/lib.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
//! use bech32::{hrp, segwit, Hrp, Bech32m};
3333
//!
3434
//! const DATA: [u8; 20] = [0xab; 20]; // Arbitrary data to be encoded.
35-
//! const ADDR: &str = "abc14w46h2at4w46h2at4w46h2at4w46h2at958ngu";
35+
//! const STRING: &str = "abc14w46h2at4w46h2at4w46h2at4w46h2at958ngu";
3636
//! const TAP_ADDR: &str = "bc1p4w46h2at4w46h2at4w46h2at4w46h2at5kreae";
3737
//!
3838
//! // Encode arbitrary data using "abc" as the human-readable part and append a bech32m checksum.
3939
//! let hrp = Hrp::parse("abc").expect("valid hrp");
40-
//! let address = bech32::encode::<Bech32m>(hrp, &DATA).expect("failed to encode address");
41-
//! assert_eq!(address, ADDR);
40+
//! let string = bech32::encode::<Bech32m>(hrp, &DATA).expect("failed to encode string");
41+
//! assert_eq!(string, STRING);
4242
//!
4343
//! // Encode arbitrary data as a Bitcoin taproot address.
4444
//! let taproot_address = segwit::encode(hrp::BC, segwit::VERSION_1, &DATA).expect("valid witness version and program");
@@ -47,7 +47,7 @@
4747
//! // No-alloc: Encode without allocating (ignoring that String::new() allocates :).
4848
//! let mut buf = String::new();
4949
//! bech32::encode_to_fmt::<Bech32m, String>(&mut buf, hrp, &DATA).expect("failed to encode to buffer");
50-
//! assert_eq!(buf, ADDR);
50+
//! assert_eq!(buf, STRING);
5151
//! # }
5252
//! ```
5353
//!
@@ -59,15 +59,15 @@
5959
//! use bech32::{hrp, segwit, Hrp, Bech32m};
6060
//!
6161
//! const DATA: [u8; 20] = [0xab; 20]; // Arbitrary data to be encoded.
62-
//! const ADDR: &str = "abc14w46h2at4w46h2at4w46h2at4w46h2at958ngu";
62+
//! const STRING: &str = "abc14w46h2at4w46h2at4w46h2at4w46h2at958ngu";
6363
//! const TAP_ADDR: &str = "bc1p4w46h2at4w46h2at4w46h2at4w46h2at5kreae";
6464
//!
6565
//! // Decode a bech32 encoded string that includes a bech32/bech32m checksum.
6666
//! //
6767
//! // The input address MUST include a valid bech32 or bech32m checksum, for individual specific
6868
//! // checksum algorithms see [`decode_bech32`], [`decode_bech32m`], [`decode_no_checksum`] or use
6969
//! // the [`primitives::decode::CheckedHrpstring`] type directly.
70-
//! let (hrp, data) = bech32::decode(&ADDR).expect("failed to decode");
70+
//! let (hrp, data) = bech32::decode(&STRING).expect("failed to decode");
7171
//! assert_eq!(hrp, Hrp::parse("abc").unwrap());
7272
//! assert_eq!(data, DATA);
7373
//!
@@ -76,7 +76,7 @@
7676
//! assert_eq!(program, DATA);
7777
//!
7878
//! // No-alloc: Decode a bech32m checksummed address without allocating.
79-
//! let p = CheckedHrpstring::new::<Bech32m>(&ADDR).expect("failed to parse address");
79+
//! let p = CheckedHrpstring::new::<Bech32m>(&STRING).expect("failed to parse string");
8080
//! assert_eq!(hrp, p.hrp());
8181
//! assert!(p.byte_iter().eq(DATA.iter().map(|&b| b))); // We yield bytes not references.
8282
//!
@@ -183,14 +183,14 @@ pub use {
183183
/// const BECH32M: &str = "abc14w46h2at4w46h2at4w46h2at4w46h2at958ngu";
184184
/// const NO_CHECKSUM: &str = "abc14w46h2at4w46h2at4w46h2at4w46h2at";
185185
///
186-
/// let (hrp, data) = decode(&BECH32).expect("valid address with valid bech32 checksum");
187-
/// let (hrp, data) = decode(&BECH32M).expect("valid address with valid bech32m checksum");
186+
/// let (hrp, data) = decode(&BECH32).expect("valid bech32 string with valid bech32 checksum");
187+
/// let (hrp, data) = decode(&BECH32M).expect("valid bech32 string with valid bech32m checksum");
188188
/// assert!(decode(&NO_CHECKSUM).is_err());
189189
///
190190
/// // You can control the checksum algorithm directly by using the [`CheckedHrpstring`] type.
191-
/// let p = CheckedHrpstring::new::<Bech32>(&BECH32).expect("valid address with valid bech32 checksum");
192-
/// let p = CheckedHrpstring::new::<Bech32m>(&BECH32M).expect("valid address with valid bech32 checksum");
193-
/// let p = CheckedHrpstring::new::<NoChecksum>(&NO_CHECKSUM).expect("valid address with no checksum");
191+
/// let p = CheckedHrpstring::new::<Bech32>(&BECH32).expect("valid bech32 string with valid bech32 checksum");
192+
/// let p = CheckedHrpstring::new::<Bech32m>(&BECH32M).expect("valid bech32 string with valid bech32 checksum");
193+
/// let p = CheckedHrpstring::new::<NoChecksum>(&NO_CHECKSUM).expect("valid bech32 string with no checksum");
194194
/// # }
195195
/// ```
196196
#[cfg(feature = "alloc")]
@@ -345,7 +345,7 @@ pub fn encode_upper_to_writer<Ck: Checksum, W: std::io::Write>(
345345
Ok(())
346346
}
347347

348-
/// An error while decoding an address.
348+
/// An error while decoding a bech32 string.
349349
#[cfg(feature = "alloc")]
350350
#[derive(Debug, Clone, PartialEq, Eq)]
351351
#[non_exhaustive]

0 commit comments

Comments
 (0)