zcash_address: Introduce UA-specific parser error type

This commit is contained in:
Jack Grigg 2021-07-12 11:44:48 +01:00
parent 01a8dba450
commit cd94b41d61
2 changed files with 28 additions and 1 deletions

View File

@ -13,6 +13,14 @@ pub enum ParseError {
NotZcash,
}
impl From<unified::ParseError> for ParseError {
fn from(e: unified::ParseError) -> Self {
match e {
unified::ParseError::InvalidEncoding => Self::InvalidEncoding,
}
}
}
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {

View File

@ -1,7 +1,9 @@
use std::convert::{TryFrom, TryInto};
use std::error::Error;
use std::fmt;
use std::iter;
use crate::{kind, ParseError};
use crate::kind;
mod f4jumble;
@ -57,6 +59,23 @@ impl From<Typecode> for u8 {
}
}
/// An error while attempting to parse a string as a Zcash address.
#[derive(Debug, PartialEq)]
pub enum ParseError {
/// The string is an invalid encoding.
InvalidEncoding,
}
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ParseError::InvalidEncoding => write!(f, "Invalid encoding"),
}
}
}
impl Error for ParseError {}
/// The set of known Receivers for Unified Addresses.
///
/// This enum is an internal-only type, and is maintained in preference order, so that the