From 271e17547ab0b4254652511acaf32511e777aa79 Mon Sep 17 00:00:00 2001 From: Jack May Date: Fri, 20 Mar 2020 18:07:37 -0700 Subject: [PATCH] Nit thiserror for pubkey (#8994) automerge --- sdk/src/pubkey.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/sdk/src/pubkey.rs b/sdk/src/pubkey.rs index 7bce24b097..87f76c7e89 100644 --- a/sdk/src/pubkey.rs +++ b/sdk/src/pubkey.rs @@ -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 DecodeError for PubkeyError { fn type_of() -> &'static str { "PubkeyError" @@ -24,20 +25,19 @@ impl DecodeError 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 DecodeError for ParsePubkeyError { + fn type_of() -> &'static str { + "ParsePubkeyError" } } -impl error::Error for ParsePubkeyError {} - impl FromStr for Pubkey { type Err = ParsePubkeyError;