32
32
//! use bech32::{hrp, segwit, Hrp, Bech32m};
33
33
//!
34
34
//! const DATA: [u8; 20] = [0xab; 20]; // Arbitrary data to be encoded.
35
- //! const ADDR : &str = "abc14w46h2at4w46h2at4w46h2at4w46h2at958ngu";
35
+ //! const STRING : &str = "abc14w46h2at4w46h2at4w46h2at4w46h2at958ngu";
36
36
//! const TAP_ADDR: &str = "bc1p4w46h2at4w46h2at4w46h2at4w46h2at5kreae";
37
37
//!
38
38
//! // Encode arbitrary data using "abc" as the human-readable part and append a bech32m checksum.
39
39
//! 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 );
42
42
//!
43
43
//! // Encode arbitrary data as a Bitcoin taproot address.
44
44
//! let taproot_address = segwit::encode(hrp::BC, segwit::VERSION_1, &DATA).expect("valid witness version and program");
47
47
//! // No-alloc: Encode without allocating (ignoring that String::new() allocates :).
48
48
//! let mut buf = String::new();
49
49
//! 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 );
51
51
//! # }
52
52
//! ```
53
53
//!
59
59
//! use bech32::{hrp, segwit, Hrp, Bech32m};
60
60
//!
61
61
//! const DATA: [u8; 20] = [0xab; 20]; // Arbitrary data to be encoded.
62
- //! const ADDR : &str = "abc14w46h2at4w46h2at4w46h2at4w46h2at958ngu";
62
+ //! const STRING : &str = "abc14w46h2at4w46h2at4w46h2at4w46h2at958ngu";
63
63
//! const TAP_ADDR: &str = "bc1p4w46h2at4w46h2at4w46h2at4w46h2at5kreae";
64
64
//!
65
65
//! // Decode a bech32 encoded string that includes a bech32/bech32m checksum.
66
66
//! //
67
67
//! // The input address MUST include a valid bech32 or bech32m checksum, for individual specific
68
68
//! // checksum algorithms see [`decode_bech32`], [`decode_bech32m`], [`decode_no_checksum`] or use
69
69
//! // 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");
71
71
//! assert_eq!(hrp, Hrp::parse("abc").unwrap());
72
72
//! assert_eq!(data, DATA);
73
73
//!
76
76
//! assert_eq!(program, DATA);
77
77
//!
78
78
//! // 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 ");
80
80
//! assert_eq!(hrp, p.hrp());
81
81
//! assert!(p.byte_iter().eq(DATA.iter().map(|&b| b))); // We yield bytes not references.
82
82
//!
@@ -166,7 +166,8 @@ pub use {
166
166
/// If this function succeeds the input string was found to be well formed (hrp, separator, bech32
167
167
/// characters), and to have either a valid bech32m checksum or a valid bech32 checksum.
168
168
///
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.
170
171
///
171
172
/// # Returns
172
173
///
@@ -182,14 +183,14 @@ pub use {
182
183
/// const BECH32M: &str = "abc14w46h2at4w46h2at4w46h2at4w46h2at958ngu";
183
184
/// const NO_CHECKSUM: &str = "abc14w46h2at4w46h2at4w46h2at4w46h2at";
184
185
///
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");
187
188
/// assert!(decode(&NO_CHECKSUM).is_err());
188
189
///
189
190
/// // 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");
193
194
/// # }
194
195
/// ```
195
196
#[ cfg( feature = "alloc" ) ]
@@ -344,7 +345,7 @@ pub fn encode_upper_to_writer<Ck: Checksum, W: std::io::Write>(
344
345
Ok ( ( ) )
345
346
}
346
347
347
- /// An error while decoding an address .
348
+ /// An error while decoding a bech32 string .
348
349
#[ cfg( feature = "alloc" ) ]
349
350
#[ derive( Debug , Clone , PartialEq , Eq ) ]
350
351
#[ non_exhaustive]
0 commit comments