Struct bech32::primitives::hrp::Hrp
source · pub struct Hrp { /* private fields */ }
Expand description
The human-readable part (human readable prefix before the ‘1’ separator).
Implementations§
source§impl Hrp
impl Hrp
sourcepub fn parse(hrp: &str) -> Result<Self, Error>
pub fn parse(hrp: &str) -> Result<Self, Error>
Parses the human-readable part checking it is valid as defined by BIP-173.
This does not check that the hrp
is an in-use HRP within Bitcoin (eg, “bc”), rather it
checks that the HRP string is valid as per the specification in BIP-173:
The human-readable part, which is intended to convey the type of data, or anything else that is relevant to the reader. This part MUST contain 1 to 83 US-ASCII characters, with each character having a value in the range [33-126]. HRP validity may be further restricted by specific applications.
sourcepub const fn parse_unchecked(hrp: &str) -> Self
pub const fn parse_unchecked(hrp: &str) -> Self
Parses the human-readable part (see Hrp::parse
for full docs).
Does not check that hrp
is valid according to BIP-173 but does check for valid ASCII
values, replacing any invalid characters with X
.
sourcepub fn to_lowercase(&self) -> String
Available on crate feature alloc
only.
pub fn to_lowercase(&self) -> String
alloc
only.Returns this human-readable part as a lowercase string.
sourcepub fn byte_iter(&self) -> ByteIter<'_> ⓘ
pub fn byte_iter(&self) -> ByteIter<'_> ⓘ
Creates a byte iterator over the ASCII byte values (ASCII characters) of this HRP.
If an uppercase HRP was parsed during object construction then this iterator will yield
uppercase ASCII char
s. For lowercase bytes see Self::lowercase_byte_iter
sourcepub fn char_iter(&self) -> CharIter<'_> ⓘ
pub fn char_iter(&self) -> CharIter<'_> ⓘ
Creates a character iterator over the ASCII characters of this HRP.
If an uppercase HRP was parsed during object construction then this iterator will yield
uppercase ASCII char
s. For lowercase bytes see Self::lowercase_char_iter
.
sourcepub fn lowercase_byte_iter(&self) -> LowercaseByteIter<'_> ⓘ
pub fn lowercase_byte_iter(&self) -> LowercaseByteIter<'_> ⓘ
Creates a lowercase iterator over the byte values (ASCII characters) of this HRP.
sourcepub fn lowercase_char_iter(&self) -> LowercaseCharIter<'_> ⓘ
pub fn lowercase_char_iter(&self) -> LowercaseCharIter<'_> ⓘ
Creates a lowercase character iterator over the ASCII characters of this HRP.
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length (number of characters) of the human-readable part.
Guaranteed to be between 1 and 83 inclusive.
sourcepub fn is_valid_segwit(&self) -> bool
pub fn is_valid_segwit(&self) -> bool
Returns true
if this HRP is valid according to the bips.
BIP-173 states that the HRP must be either “bc” or “tb”.
sourcepub fn is_valid_on_mainnet(&self) -> bool
pub fn is_valid_on_mainnet(&self) -> bool
Returns true
if this HRP is valid on the Bitcoin network i.e., HRP is “bc”.
sourcepub fn is_valid_on_testnet(&self) -> bool
pub fn is_valid_on_testnet(&self) -> bool
Returns true
if this HRP is valid on the Bitcoin testnet network i.e., HRP is “tb”.
sourcepub fn is_valid_on_signet(&self) -> bool
pub fn is_valid_on_signet(&self) -> bool
Returns true
if this HRP is valid on the Bitcoin signet network i.e., HRP is “tb”.
sourcepub fn is_valid_on_regtest(&self) -> bool
pub fn is_valid_on_regtest(&self) -> bool
Returns true
if this HRP is valid on the Bitcoin regtest network i.e., HRP is “bcrt”.
Trait Implementations§
source§impl Display for Hrp
impl Display for Hrp
Displays the human-readable part.
If an uppercase HRP was parsed during object construction then the returned string will be
in uppercase also. For a lowercase string see Self::to_lowercase
.
source§impl Ord for Hrp
impl Ord for Hrp
Case insensitive comparison.
source§impl PartialEq for Hrp
impl PartialEq for Hrp
Case insensitive comparison.
source§impl PartialOrd for Hrp
impl PartialOrd for Hrp
Case insensitive comparison.
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more