@@ -122,6 +122,7 @@ impl<'s> UncheckedHrpstring<'s> {
122
122
/// Parses an bech32 encode string and constructs a [`UncheckedHrpstring`] object.
123
123
///
124
124
/// Checks for valid ASCII values, does not validate the checksum.
125
+ #[ inline]
125
126
pub fn new ( s : & ' s str ) -> Result < Self , UncheckedHrpstringError > {
126
127
let sep_pos = check_characters ( s) ?;
127
128
let ( hrp, data) = s. split_at ( sep_pos) ;
@@ -135,9 +136,11 @@ impl<'s> UncheckedHrpstring<'s> {
135
136
}
136
137
137
138
/// Returns the human-readable part.
139
+ #[ inline]
138
140
pub fn hrp ( & self ) -> Hrp { self . hrp }
139
141
140
142
/// Validates that data has a valid checksum for the `Ck` algorithm and returns a [`CheckedHrpstring`].
143
+ #[ inline]
141
144
pub fn validate_and_remove_checksum < Ck : Checksum > (
142
145
self ,
143
146
) -> Result < CheckedHrpstring < ' s > , ChecksumError > {
@@ -151,12 +154,14 @@ impl<'s> UncheckedHrpstring<'s> {
151
154
/// This is useful if you do not know which checksum algorithm was used and wish to validate
152
155
/// against multiple algorithms consecutively. If this function returns `true` then call
153
156
/// `remove_checksum` to get a [`CheckedHrpstring`].
157
+ #[ inline]
154
158
pub fn has_valid_checksum < Ck : Checksum > ( & self ) -> bool {
155
159
self . validate_checksum :: < Ck > ( ) . is_ok ( )
156
160
}
157
161
158
162
/// Validates that data has a valid checksum for the `Ck` algorithm (this may mean an empty
159
163
/// checksum if `NoChecksum` is used).
164
+ #[ inline]
160
165
pub fn validate_checksum < Ck : Checksum > ( & self ) -> Result < ( ) , ChecksumError > {
161
166
use ChecksumError :: * ;
162
167
@@ -193,6 +198,7 @@ impl<'s> UncheckedHrpstring<'s> {
193
198
/// # Panics
194
199
///
195
200
/// May panic if data is not valid.
201
+ #[ inline]
196
202
pub fn remove_checksum < Ck : Checksum > ( self ) -> CheckedHrpstring < ' s > {
197
203
let data_len = self . data . len ( ) - Ck :: CHECKSUM_LENGTH ;
198
204
@@ -237,24 +243,28 @@ impl<'s> CheckedHrpstring<'s> {
237
243
/// If you are validating the checksum multiple times consider using [`UncheckedHrpstring`].
238
244
///
239
245
/// This is equivalent to `UncheckedHrpstring::new().validate_and_remove_checksum::<CK>()`.
246
+ #[ inline]
240
247
pub fn new < Ck : Checksum > ( s : & ' s str ) -> Result < Self , CheckedHrpstringError > {
241
248
let unchecked = UncheckedHrpstring :: new ( s) ?;
242
249
let checked = unchecked. validate_and_remove_checksum :: < Ck > ( ) ?;
243
250
Ok ( checked)
244
251
}
245
252
246
253
/// Returns the human-readable part.
254
+ #[ inline]
247
255
pub fn hrp ( & self ) -> Hrp { self . hrp }
248
256
249
257
/// Returns an iterator that yields the data part of the parsed bech32 encoded string.
250
258
///
251
259
/// Converts the ASCII bytes representing field elements to the respective field elements, then
252
260
/// converts the stream of field elements to a stream of bytes.
261
+ #[ inline]
253
262
pub fn byte_iter ( & self ) -> ByteIter {
254
263
ByteIter { iter : AsciiToFe32Iter { iter : self . data . iter ( ) . copied ( ) } . fes_to_bytes ( ) }
255
264
}
256
265
257
266
/// Converts this type to a [`SegwitHrpstring`] after validating the witness and HRP.
267
+ #[ inline]
258
268
pub fn validate_segwit ( mut self ) -> Result < SegwitHrpstring < ' s > , SegwitHrpstringError > {
259
269
if self . data . is_empty ( ) {
260
270
return Err ( SegwitHrpstringError :: MissingWitnessVersion ) ;
@@ -362,6 +372,7 @@ impl<'s> SegwitHrpstring<'s> {
362
372
///
363
373
/// NOTE: We do not enforce any restrictions on the HRP, use [`SegwitHrpstring::has_valid_hrp`]
364
374
/// to get strict BIP conformance (also [`Hrp::is_valid_on_mainnet`] and friends).
375
+ #[ inline]
365
376
pub fn new ( s : & ' s str ) -> Result < Self , SegwitHrpstringError > {
366
377
let unchecked = UncheckedHrpstring :: new ( s) ?;
367
378
@@ -391,6 +402,7 @@ impl<'s> SegwitHrpstring<'s> {
391
402
///
392
403
/// [BIP-173]: https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki
393
404
/// [BIP-350]: https://github.com/bitcoin/bips/blob/master/bip-0350.mediawiki
405
+ #[ inline]
394
406
pub fn new_bech32 ( s : & ' s str ) -> Result < Self , SegwitHrpstringError > {
395
407
let unchecked = UncheckedHrpstring :: new ( s) ?;
396
408
@@ -409,12 +421,15 @@ impl<'s> SegwitHrpstring<'s> {
409
421
/// BIP-173 requires that the HRP is "bc" or "tb" but software in the Bitcoin ecosystem uses
410
422
/// other HRPs, specifically "bcrt" for regtest addresses. We provide this function in order to
411
423
/// be BIP-173 compliant but their are no restrictions on the HRP of [`SegwitHrpstring`].
424
+ #[ inline]
412
425
pub fn has_valid_hrp ( & self ) -> bool { self . hrp ( ) . is_valid_segwit ( ) }
413
426
414
427
/// Returns the human-readable part.
428
+ #[ inline]
415
429
pub fn hrp ( & self ) -> Hrp { self . hrp }
416
430
417
431
/// Returns the witness version.
432
+ #[ inline]
418
433
pub fn witness_version ( & self ) -> Fe32 { self . witness_version }
419
434
420
435
/// Returns an iterator that yields the data part, excluding the witness version, of the parsed
@@ -424,6 +439,7 @@ impl<'s> SegwitHrpstring<'s> {
424
439
/// converts the stream of field elements to a stream of bytes.
425
440
///
426
441
/// Use `self.witness_version()` to get the witness version.
442
+ #[ inline]
427
443
pub fn byte_iter ( & self ) -> ByteIter {
428
444
ByteIter { iter : AsciiToFe32Iter { iter : self . data . iter ( ) . copied ( ) } . fes_to_bytes ( ) }
429
445
}
@@ -472,11 +488,14 @@ pub struct ByteIter<'s> {
472
488
473
489
impl < ' s > Iterator for ByteIter < ' s > {
474
490
type Item = u8 ;
491
+ #[ inline]
475
492
fn next ( & mut self ) -> Option < u8 > { self . iter . next ( ) }
493
+ #[ inline]
476
494
fn size_hint ( & self ) -> ( usize , Option < usize > ) { self . iter . size_hint ( ) }
477
495
}
478
496
479
497
impl < ' s > ExactSizeIterator for ByteIter < ' s > {
498
+ #[ inline]
480
499
fn len ( & self ) -> usize { self . iter . len ( ) }
481
500
}
482
501
@@ -487,7 +506,9 @@ pub struct Fe32Iter<'s> {
487
506
488
507
impl < ' s > Iterator for Fe32Iter < ' s > {
489
508
type Item = Fe32 ;
509
+ #[ inline]
490
510
fn next ( & mut self ) -> Option < Fe32 > { self . iter . next ( ) }
511
+ #[ inline]
491
512
fn size_hint ( & self ) -> ( usize , Option < usize > ) { self . iter . size_hint ( ) }
492
513
}
493
514
@@ -507,7 +528,9 @@ where
507
528
I : Iterator < Item = u8 > ,
508
529
{
509
530
type Item = Fe32 ;
531
+ #[ inline]
510
532
fn next ( & mut self ) -> Option < Fe32 > { self . iter . next ( ) . map ( Fe32 :: from_char_unchecked) }
533
+ #[ inline]
511
534
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
512
535
// Each ASCII character is an fe32 so iterators are the same size.
513
536
self . iter . size_hint ( )
@@ -518,6 +541,7 @@ impl<I> ExactSizeIterator for AsciiToFe32Iter<I>
518
541
where
519
542
I : Iterator < Item = u8 > + ExactSizeIterator ,
520
543
{
544
+ #[ inline]
521
545
fn len ( & self ) -> usize { self . iter . len ( ) }
522
546
}
523
547
0 commit comments