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");
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//!
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//!
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//!
@@ -166,7 +166,8 @@ pub use {
166166/// If this function succeeds the input string was found to be well formed (hrp, separator, bech32
167167/// characters), and to have either a valid bech32m checksum or a valid bech32 checksum.
168168///
169- /// If your input string has no checksum use the [`CheckedHrpstring`] constructor, which allows selecting the checksum algorithm explicitly.
169+ /// If your input string has no checksum use the [`CheckedHrpstring`] constructor, which allows
170+ /// selecting the checksum algorithm explicitly.
170171///
171172/// # Returns
172173///
@@ -182,14 +183,14 @@ pub use {
182183/// const BECH32M: &str = "abc14w46h2at4w46h2at4w46h2at4w46h2at958ngu";
183184/// const NO_CHECKSUM: &str = "abc14w46h2at4w46h2at4w46h2at4w46h2at";
184185///
185- /// let (hrp, data) = decode(&BECH32).expect("valid address with valid bech32 checksum");
186- /// 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");
187188/// assert!(decode(&NO_CHECKSUM).is_err());
188189///
189190/// // You can control the checksum algorithm directly by using the [`CheckedHrpstring`] type.
190- /// let p = CheckedHrpstring::new::<Bech32>(&BECH32).expect("valid address with valid bech32 checksum");
191- /// let p = CheckedHrpstring::new::<Bech32m>(&BECH32M).expect("valid address with valid bech32 checksum");
192- /// 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");
193194/// # }
194195/// ```
195196#[ cfg( feature = "alloc" ) ]
@@ -344,7 +345,7 @@ pub fn encode_upper_to_writer<Ck: Checksum, W: std::io::Write>(
344345 Ok ( ( ) )
345346}
346347
347- /// An error while decoding an address .
348+ /// An error while decoding a bech32 string .
348349#[ cfg( feature = "alloc" ) ]
349350#[ derive( Debug , Clone , PartialEq , Eq ) ]
350351#[ non_exhaustive]
0 commit comments