@@ -122,6 +122,7 @@ impl<'s> UncheckedHrpstring<'s> {
122122 /// Parses an bech32 encode string and constructs a [`UncheckedHrpstring`] object.
123123 ///
124124 /// Checks for valid ASCII values, does not validate the checksum.
125+ #[ inline]
125126 pub fn new ( s : & ' s str ) -> Result < Self , UncheckedHrpstringError > {
126127 let sep_pos = check_characters ( s) ?;
127128 let ( hrp, data) = s. split_at ( sep_pos) ;
@@ -135,9 +136,11 @@ impl<'s> UncheckedHrpstring<'s> {
135136 }
136137
137138 /// Returns the human-readable part.
139+ #[ inline]
138140 pub fn hrp ( & self ) -> Hrp { self . hrp }
139141
140142 /// Validates that data has a valid checksum for the `Ck` algorithm and returns a [`CheckedHrpstring`].
143+ #[ inline]
141144 pub fn validate_and_remove_checksum < Ck : Checksum > (
142145 self ,
143146 ) -> Result < CheckedHrpstring < ' s > , ChecksumError > {
@@ -151,12 +154,14 @@ impl<'s> UncheckedHrpstring<'s> {
151154 /// This is useful if you do not know which checksum algorithm was used and wish to validate
152155 /// against multiple algorithms consecutively. If this function returns `true` then call
153156 /// `remove_checksum` to get a [`CheckedHrpstring`].
157+ #[ inline]
154158 pub fn has_valid_checksum < Ck : Checksum > ( & self ) -> bool {
155159 self . validate_checksum :: < Ck > ( ) . is_ok ( )
156160 }
157161
158162 /// Validates that data has a valid checksum for the `Ck` algorithm (this may mean an empty
159163 /// checksum if `NoChecksum` is used).
164+ #[ inline]
160165 pub fn validate_checksum < Ck : Checksum > ( & self ) -> Result < ( ) , ChecksumError > {
161166 use ChecksumError :: * ;
162167
@@ -193,6 +198,7 @@ impl<'s> UncheckedHrpstring<'s> {
193198 /// # Panics
194199 ///
195200 /// May panic if data is not valid.
201+ #[ inline]
196202 pub fn remove_checksum < Ck : Checksum > ( self ) -> CheckedHrpstring < ' s > {
197203 let data_len = self . data . len ( ) - Ck :: CHECKSUM_LENGTH ;
198204
@@ -237,24 +243,28 @@ impl<'s> CheckedHrpstring<'s> {
237243 /// If you are validating the checksum multiple times consider using [`UncheckedHrpstring`].
238244 ///
239245 /// This is equivalent to `UncheckedHrpstring::new().validate_and_remove_checksum::<CK>()`.
246+ #[ inline]
240247 pub fn new < Ck : Checksum > ( s : & ' s str ) -> Result < Self , CheckedHrpstringError > {
241248 let unchecked = UncheckedHrpstring :: new ( s) ?;
242249 let checked = unchecked. validate_and_remove_checksum :: < Ck > ( ) ?;
243250 Ok ( checked)
244251 }
245252
246253 /// Returns the human-readable part.
254+ #[ inline]
247255 pub fn hrp ( & self ) -> Hrp { self . hrp }
248256
249257 /// Returns an iterator that yields the data part of the parsed bech32 encoded string.
250258 ///
251259 /// Converts the ASCII bytes representing field elements to the respective field elements, then
252260 /// converts the stream of field elements to a stream of bytes.
261+ #[ inline]
253262 pub fn byte_iter ( & self ) -> ByteIter {
254263 ByteIter { iter : AsciiToFe32Iter { iter : self . data . iter ( ) . copied ( ) } . fes_to_bytes ( ) }
255264 }
256265
257266 /// Converts this type to a [`SegwitHrpstring`] after validating the witness and HRP.
267+ #[ inline]
258268 pub fn validate_segwit ( mut self ) -> Result < SegwitHrpstring < ' s > , SegwitHrpstringError > {
259269 if self . data . is_empty ( ) {
260270 return Err ( SegwitHrpstringError :: MissingWitnessVersion ) ;
@@ -362,6 +372,7 @@ impl<'s> SegwitHrpstring<'s> {
362372 ///
363373 /// NOTE: We do not enforce any restrictions on the HRP, use [`SegwitHrpstring::has_valid_hrp`]
364374 /// to get strict BIP conformance (also [`Hrp::is_valid_on_mainnet`] and friends).
375+ #[ inline]
365376 pub fn new ( s : & ' s str ) -> Result < Self , SegwitHrpstringError > {
366377 let unchecked = UncheckedHrpstring :: new ( s) ?;
367378
@@ -391,6 +402,7 @@ impl<'s> SegwitHrpstring<'s> {
391402 ///
392403 /// [BIP-173]: https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki
393404 /// [BIP-350]: https://github.com/bitcoin/bips/blob/master/bip-0350.mediawiki
405+ #[ inline]
394406 pub fn new_bech32 ( s : & ' s str ) -> Result < Self , SegwitHrpstringError > {
395407 let unchecked = UncheckedHrpstring :: new ( s) ?;
396408
@@ -409,12 +421,15 @@ impl<'s> SegwitHrpstring<'s> {
409421 /// BIP-173 requires that the HRP is "bc" or "tb" but software in the Bitcoin ecosystem uses
410422 /// other HRPs, specifically "bcrt" for regtest addresses. We provide this function in order to
411423 /// be BIP-173 compliant but their are no restrictions on the HRP of [`SegwitHrpstring`].
424+ #[ inline]
412425 pub fn has_valid_hrp ( & self ) -> bool { self . hrp ( ) . is_valid_segwit ( ) }
413426
414427 /// Returns the human-readable part.
428+ #[ inline]
415429 pub fn hrp ( & self ) -> Hrp { self . hrp }
416430
417431 /// Returns the witness version.
432+ #[ inline]
418433 pub fn witness_version ( & self ) -> Fe32 { self . witness_version }
419434
420435 /// Returns an iterator that yields the data part, excluding the witness version, of the parsed
@@ -424,6 +439,7 @@ impl<'s> SegwitHrpstring<'s> {
424439 /// converts the stream of field elements to a stream of bytes.
425440 ///
426441 /// Use `self.witness_version()` to get the witness version.
442+ #[ inline]
427443 pub fn byte_iter ( & self ) -> ByteIter {
428444 ByteIter { iter : AsciiToFe32Iter { iter : self . data . iter ( ) . copied ( ) } . fes_to_bytes ( ) }
429445 }
@@ -472,11 +488,14 @@ pub struct ByteIter<'s> {
472488
473489impl < ' s > Iterator for ByteIter < ' s > {
474490 type Item = u8 ;
491+ #[ inline]
475492 fn next ( & mut self ) -> Option < u8 > { self . iter . next ( ) }
493+ #[ inline]
476494 fn size_hint ( & self ) -> ( usize , Option < usize > ) { self . iter . size_hint ( ) }
477495}
478496
479497impl < ' s > ExactSizeIterator for ByteIter < ' s > {
498+ #[ inline]
480499 fn len ( & self ) -> usize { self . iter . len ( ) }
481500}
482501
@@ -487,7 +506,9 @@ pub struct Fe32Iter<'s> {
487506
488507impl < ' s > Iterator for Fe32Iter < ' s > {
489508 type Item = Fe32 ;
509+ #[ inline]
490510 fn next ( & mut self ) -> Option < Fe32 > { self . iter . next ( ) }
511+ #[ inline]
491512 fn size_hint ( & self ) -> ( usize , Option < usize > ) { self . iter . size_hint ( ) }
492513}
493514
@@ -507,7 +528,9 @@ where
507528 I : Iterator < Item = u8 > ,
508529{
509530 type Item = Fe32 ;
531+ #[ inline]
510532 fn next ( & mut self ) -> Option < Fe32 > { self . iter . next ( ) . map ( Fe32 :: from_char_unchecked) }
533+ #[ inline]
511534 fn size_hint ( & self ) -> ( usize , Option < usize > ) {
512535 // Each ASCII character is an fe32 so iterators are the same size.
513536 self . iter . size_hint ( )
@@ -518,6 +541,7 @@ impl<I> ExactSizeIterator for AsciiToFe32Iter<I>
518541where
519542 I : Iterator < Item = u8 > + ExactSizeIterator ,
520543{
544+ #[ inline]
521545 fn len ( & self ) -> usize { self . iter . len ( ) }
522546}
523547
0 commit comments