Skip to main content

Err

Enum Err 

Source
pub enum Err {
    InvalidLen(usize),
    InvalidChar(usize),
    MixedCase(usize, usize),
    MissingSeparator,
    InvalidHrpLen(usize),
    InvalidChecksum,
}
Expand description

String parse error.

§Examples

Try to parse an empty string:

use pbech32::{Bech32, Err};
let s = ""; // empty string
assert_eq!(s.parse::<Bech32>(), Err(Err::InvalidLen(0)));

Try to parse a string with an invalid character:

use pbech32::{Bech32, Err};
let s = "a 1xxxxxx"; // string with invalid bech32 character
assert_eq!(s.parse::<Bech32>(), Err(Err::InvalidChar(1)));

Variants§

§

InvalidLen(usize)

Invalid string length.

The length of a Bech32 string must be in the range 8...

The error field contains the invalid length.

Note: BIP173 limits the maximum string length to 90 characters; this library does not have a maximum string length.

§Example

Try to parse an empty string:

use pbech32::{Bech32, Err};
let s = ""; // empty string
assert_eq!(s.parse::<Bech32>(), Err(Err::InvalidLen(0)));
§

InvalidChar(usize)

String contains an invalid character at the given position.

A Bech32 string must only contain alphanumeric ASCII characters.

The error field indicates the first invalid character position in the string.

§Example

Try to parse a string with an invalid character at position 1:

use pbech32::{Bech32, Err};
let s = "a 1xxxxxx"; // string with invalid bech32 character
assert_eq!(s.parse::<Bech32>(), Err(Err::InvalidChar(1)));
§

MixedCase(usize, usize)

String contains both uppercase and lowercase characters.

A Bech32 string must not contain both uppercase and lowercase characters.

The error fields indicate the first lowercase character position and in the string the first uppercase character position in the string, respectively.

§Example

Try to parse a string with an lowercase character at position 0 and an uppercase character at position 1:

use pbech32::{Bech32, Err};
let s = "Ab1xxxxxx"; // string with mixed-case characters
assert_eq!(s.parse::<Bech32>(), Err(Err::MixedCase(1, 0)));
§

MissingSeparator

String is missing a separator character.

A Bech32 string must contain a 1 character between the the human-readable part and the data part.

§Example

Try to parse a string which does not have a separator between the human-readable part and the data part:

use pbech32::{Bech32, Err};
let s = "avxxxxxx"; // string without separator
assert_eq!(s.parse::<Bech32>(), Err(Err::MissingSeparator));
§

InvalidHrpLen(usize)

Length of Human-readable part (HRP) of string is invalid.

The length of the human-readable part of a Bech32 string must be in the range [1..84].

The error field contains the invalid human-readable part length.

§Examples

Try to parse a string with an empty human-readable part:

use pbech32::{Bech32, Err};
let s = "1axxxxxx"; // string with empty HRP
assert_eq!(s.parse::<Bech32>(), Err(Err::InvalidHrpLen(0)));

Try to parse a string with a human-readable part that is too long:

use pbech32::{Bech32, Err};
let s = str::repeat("a", 84) + "1xxxxxx"; // string with long HRP
assert_eq!(s.parse::<Bech32>(), Err(Err::InvalidHrpLen(84)));
§

InvalidChecksum

Invalid checksum.

§Example

Try to parse a string with an invalid checksum:

use pbech32::{Bech32, Err};
let s = "a1xxxxxx"; // string with invalid checksum
assert_eq!(s.parse::<Bech32>(), Err(Err::InvalidChecksum));

Trait Implementations§

Source§

impl Clone for Err

Source§

fn clone(&self) -> Err

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Err

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Err

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for Err

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl PartialEq for Err

Source§

fn eq(&self, other: &Err) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Err

Source§

impl Eq for Err

Source§

impl StructuralPartialEq for Err

Auto Trait Implementations§

§

impl Freeze for Err

§

impl RefUnwindSafe for Err

§

impl Send for Err

§

impl Sync for Err

§

impl Unpin for Err

§

impl UnsafeUnpin for Err

§

impl UnwindSafe for Err

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.