diff --git a/src/lib.rs b/src/lib.rs index 0139c355a..a45652f6d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -38,13 +38,13 @@ //! use bech32::{hrp, segwit, Hrp, Bech32m}; //! //! const DATA: [u8; 20] = [0xab; 20]; // Arbitrary data to be encoded. -//! const ADDR: &str = "abc14w46h2at4w46h2at4w46h2at4w46h2at958ngu"; +//! const STRING: &str = "abc14w46h2at4w46h2at4w46h2at4w46h2at958ngu"; //! const TAP_ADDR: &str = "bc1p4w46h2at4w46h2at4w46h2at4w46h2at5kreae"; //! //! // Encode arbitrary data using "abc" as the human-readable part and append a bech32m checksum. //! let hrp = Hrp::parse("abc").expect("valid hrp"); -//! let address = bech32::encode::(hrp, &DATA).expect("failed to encode address"); -//! assert_eq!(address, ADDR); +//! let string = bech32::encode::(hrp, &DATA).expect("failed to encode string"); +//! assert_eq!(string, STRING); //! //! // Encode arbitrary data as a Bitcoin taproot address. //! let taproot_address = segwit::encode(hrp::BC, segwit::VERSION_1, &DATA).expect("valid witness version and program"); @@ -53,7 +53,7 @@ //! // No-alloc: Encode without allocating (ignoring that String::new() allocates :). //! let mut buf = String::new(); //! bech32::encode_to_fmt::(&mut buf, hrp, &DATA).expect("failed to encode to buffer"); -//! assert_eq!(buf, ADDR); +//! assert_eq!(buf, STRING); //! # } //! ``` //! @@ -65,7 +65,7 @@ //! use bech32::{hrp, segwit, Hrp, Bech32m}; //! //! const DATA: [u8; 20] = [0xab; 20]; // Arbitrary data to be encoded. -//! const ADDR: &str = "abc14w46h2at4w46h2at4w46h2at4w46h2at958ngu"; +//! const STRING: &str = "abc14w46h2at4w46h2at4w46h2at4w46h2at958ngu"; //! const TAP_ADDR: &str = "bc1p4w46h2at4w46h2at4w46h2at4w46h2at5kreae"; //! //! // Decode a bech32 encoded string that includes a bech32/bech32m checksum. @@ -73,7 +73,7 @@ //! // The input address MUST include a valid bech32 or bech32m checksum, for individual specific //! // checksum algorithms see [`decode_bech32`], [`decode_bech32m`], [`decode_no_checksum`] or use //! // the [`primitives::decode::CheckedHrpstring`] type directly. -//! let (hrp, data) = bech32::decode(&ADDR).expect("failed to decode"); +//! let (hrp, data) = bech32::decode(&STRING).expect("failed to decode"); //! assert_eq!(hrp, Hrp::parse("abc").unwrap()); //! assert_eq!(data, DATA); //! @@ -82,7 +82,7 @@ //! assert_eq!(program, DATA); //! //! // No-alloc: Decode a bech32m checksummed address without allocating. -//! let p = CheckedHrpstring::new::(&ADDR).expect("failed to parse address"); +//! let p = CheckedHrpstring::new::(&STRING).expect("failed to parse string"); //! assert_eq!(hrp, p.hrp()); //! assert!(p.byte_iter().eq(DATA.iter().map(|&b| b))); // We yield bytes not references. //! @@ -197,14 +197,14 @@ pub use { /// const BECH32M: &str = "abc14w46h2at4w46h2at4w46h2at4w46h2at958ngu"; /// const NO_CHECKSUM: &str = "abc14w46h2at4w46h2at4w46h2at4w46h2at"; /// -/// let (hrp, data) = decode(&BECH32).expect("valid address with valid bech32 checksum"); -/// let (hrp, data) = decode(&BECH32M).expect("valid address with valid bech32m checksum"); +/// let (hrp, data) = decode(&BECH32).expect("valid bech32 string with valid bech32 checksum"); +/// let (hrp, data) = decode(&BECH32M).expect("valid bech32 string with valid bech32m checksum"); /// assert!(decode(&NO_CHECKSUM).is_err()); /// /// // You can control the checksum algorithm directly by using the [`CheckedHrpstring`] type. -/// let p = CheckedHrpstring::new::(&BECH32).expect("valid address with valid bech32 checksum"); -/// let p = CheckedHrpstring::new::(&BECH32M).expect("valid address with valid bech32 checksum"); -/// let p = CheckedHrpstring::new::(&NO_CHECKSUM).expect("valid address with no checksum"); +/// let p = CheckedHrpstring::new::(&BECH32).expect("valid bech32 string with valid bech32 checksum"); +/// let p = CheckedHrpstring::new::(&BECH32M).expect("valid bech32 string with valid bech32 checksum"); +/// let p = CheckedHrpstring::new::(&NO_CHECKSUM).expect("valid bech32 string with no checksum"); /// # } /// ``` #[cfg(feature = "alloc")] @@ -406,7 +406,7 @@ pub fn encoded_length(hrp: Hrp, data: &[u8]) -> usize { hrp.len() + 1 + iter.len() + Ck::CHECKSUM_LENGTH // +1 for separator } -/// An error while decoding an address. +/// An error while decoding a bech32 string. #[cfg(feature = "alloc")] #[derive(Debug, Clone, PartialEq, Eq)] #[non_exhaustive] @@ -622,7 +622,7 @@ mod tests { #[test] fn encoded_length_works() { let s = "test1lu08d6qejxtdg4y5r3zarvary0c5xw7kmz4lky"; - let (hrp, data) = decode(s).expect("failed to decode valid address"); + let (hrp, data) = decode(s).expect("failed to decode valid bech32 string"); let encoded = encode::(hrp, &data).expect("failed to encode string"); let want = encoded.len();