From b67e220ede65f3b5a8e7c0f4863ff48242f9b623 Mon Sep 17 00:00:00 2001 From: Jonathan Johnson Date: Thu, 24 Aug 2023 08:02:16 -0700 Subject: [PATCH] Removing undocumented KindOrClass I noticed this new enum since 2.0 was slightly redundant, so I removed it and just used Kind in its place. --- pot/src/error.rs | 23 +++-------------------- pot/src/format.rs | 11 +++++------ 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/pot/src/error.rs b/pot/src/error.rs index 99ce52cc..2cc75b03 100644 --- a/pot/src/error.rs +++ b/pot/src/error.rs @@ -32,11 +32,11 @@ pub enum Error { /// An unknown kind was encountered. Generally a sign that something else has been parsed incorrectly. InvalidKind(u8), /// Encountered an unexpected atom kind. - UnexpectedKind(Kind, KindOrClass), + UnexpectedKind(Kind, Kind), /// A requested symbol id was not found. UnknownSymbol(u64), /// An unsupported byte count for a numeric type was encountered. - UnsupportedByteCount(KindOrClass, usize), + UnsupportedByteCount(Kind, usize), /// An atom header was incorrectly formatted. InvalidAtomHeader, /// The amount of data read exceeds the configured maximum number of bytes. @@ -70,30 +70,13 @@ impl Display for Error { f.write_str("the deserialized value is larger than the allowed allocation limit") } Error::UnsupportedByteCount(kind, count) => { - write!(f, "unexpected {kind} byte count ({count})") + write!(f, "unexpected {kind:?} byte count ({count})") } Error::UnknownSpecial(err) => Display::fmt(err, f), } } } -#[derive(Debug)] -pub enum KindOrClass { - Kind(Kind), - Float, - Integer, -} - -impl Display for KindOrClass { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - KindOrClass::Kind(kind) => Debug::fmt(kind, f), - KindOrClass::Float => f.write_str("float"), - KindOrClass::Integer => f.write_str("integer"), - } - } -} - impl std::error::Error for Error {} impl From for Error { diff --git a/pot/src/format.rs b/pot/src/format.rs index d223032f..84978347 100644 --- a/pot/src/format.rs +++ b/pot/src/format.rs @@ -6,7 +6,6 @@ use serde::{Deserialize, Serialize}; pub(crate) const CURRENT_VERSION: u8 = 0; -use crate::error::KindOrClass; use crate::reader::{BufferedBytes, Reader}; use crate::Error; /// Writes an atom header into `writer`. @@ -934,7 +933,7 @@ impl Integer { 6 => Ok(InnerInteger::I64(reader.read_i48::()?)), 8 => Ok(InnerInteger::I64(reader.read_i64::()?)), 16 => Ok(InnerInteger::I128(reader.read_i128::()?)), - count => Err(Error::UnsupportedByteCount(KindOrClass::Integer, count)), + count => Err(Error::UnsupportedByteCount(kind, count)), }, Kind::UInt => match byte_len { 1 => Ok(InnerInteger::U8(reader.read_u8()?)), @@ -944,9 +943,9 @@ impl Integer { 6 => Ok(InnerInteger::U64(reader.read_u48::()?)), 8 => Ok(InnerInteger::U64(reader.read_u64::()?)), 16 => Ok(InnerInteger::U128(reader.read_u128::()?)), - count => Err(Error::UnsupportedByteCount(KindOrClass::Integer, count)), + count => Err(Error::UnsupportedByteCount(kind, count)), }, - _ => Err(Error::UnexpectedKind(kind, KindOrClass::Integer)), + _ => Err(Error::UnexpectedKind(kind, Kind::Int)), } .map(Integer) } @@ -1262,10 +1261,10 @@ impl Float { 2 => Ok(Self::from(read_f16(reader)?)), 4 => Ok(Self::from(reader.read_f32::()?)), 8 => Ok(Self::from(reader.read_f64::()?)), - count => Err(Error::UnsupportedByteCount(KindOrClass::Float, count)), + count => Err(Error::UnsupportedByteCount(Kind::Float, count)), } } else { - Err(Error::UnexpectedKind(kind, KindOrClass::Float)) + Err(Error::UnexpectedKind(kind, Kind::Float)) } } }