Nit thiserror for pubkey (#8994)

automerge
This commit is contained in:
Jack May 2020-03-20 18:07:37 -07:00 committed by GitHub
parent e28368ff1b
commit 271e17547a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 9 deletions

View File

@ -1,6 +1,8 @@
use crate::{hash::hashv, program_utils::DecodeError};
use num_derive::{FromPrimitive, ToPrimitive};
use std::{convert::TryFrom, error, fmt, mem, str::FromStr};
#[cfg(not(feature = "program"))]
use std::error;
use std::{convert::TryFrom, fmt, mem, str::FromStr};
use thiserror::Error;
pub use bs58;
@ -13,7 +15,6 @@ pub enum PubkeyError {
#[error("length of requested seed is too long")]
MaxSeedLengthExceeded,
}
impl<T> DecodeError<T> for PubkeyError {
fn type_of() -> &'static str {
"PubkeyError"
@ -24,20 +25,19 @@ impl<T> DecodeError<T> for PubkeyError {
#[derive(Serialize, Deserialize, Clone, Copy, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct Pubkey([u8; 32]);
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Error, Debug, Serialize, Clone, PartialEq, FromPrimitive, ToPrimitive)]
pub enum ParsePubkeyError {
#[error("String is the wrong size")]
WrongSize,
#[error("Invalid Base58 string")]
Invalid,
}
impl fmt::Display for ParsePubkeyError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "ParsePubkeyError: {:?}", self)
impl<T> DecodeError<T> for ParsePubkeyError {
fn type_of() -> &'static str {
"ParsePubkeyError"
}
}
impl error::Error for ParsePubkeyError {}
impl FromStr for Pubkey {
type Err = ParsePubkeyError;