pub struct Hrp(pub String);Expand description
Human-readable part (HRP) of Bech32 structure.
A valid HRP string must meet all following conditions:
- String length must be in the range
1..84. - Must only contain ASCII characters in the range
33..127. - Must not contain a mixture of uppercase and lowercase alphabetic characters.
Note: Stored as lowercase.
§Examples
Parse string as Hrp:
use pbech32::Hrp;
let s = "testhrp"; // hrp string
let hrp: Hrp = s.parse()?; // parse stringConvert Hrp to a string:
use pbech32::Hrp;
let s = "foobar"; // hrp string
let hrp: Hrp = s.parse()?; // parse string
assert_eq!(hrp.to_string(), "foobar"); // check resultConvert Hrp to a &str with Hrp::as_ref():
use pbech32::Hrp;
let s = "foobar"; // hrp string
let hrp: Hrp = s.parse()?; // parse string
assert_eq!(hrp.as_ref(), "foobar"); // check resultStrings which contain all uppercase characters are converted to
lowercase when parsed as an Hrp:
use pbech32::Hrp;
let hrp: Hrp = "TESTHRP".parse()?; // parse hrp string
assert_eq!(hrp.to_string(), "testhrp"); // check resultParsing will fail if the given string is not a valid human-readable part. For example, here is a mixed-case string:
use pbech32::{Err, Hrp};
let s = "FOObar"; // mixed-case string
let got = s.parse::<Hrp>(); // parse string
assert_eq!(got, Err(Err::MixedCase(3, 0))); // check resultTuple Fields§
§0: StringTrait Implementations§
impl Eq for Hrp
impl StructuralPartialEq for Hrp
Auto Trait Implementations§
impl Freeze for Hrp
impl RefUnwindSafe for Hrp
impl Send for Hrp
impl Sync for Hrp
impl Unpin for Hrp
impl UnsafeUnpin for Hrp
impl UnwindSafe for Hrp
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more