Skip to content

Commit

Permalink
Removing undocumented KindOrClass
Browse files Browse the repository at this point in the history
I noticed this new enum since 2.0 was slightly redundant, so I removed
it and just used Kind in its place.
  • Loading branch information
ecton committed Aug 24, 2023
1 parent da883d8 commit b67e220
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 26 deletions.
23 changes: 3 additions & 20 deletions pot/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<io::Error> for Error {
Expand Down
11 changes: 5 additions & 6 deletions pot/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -934,7 +933,7 @@ impl Integer {
6 => Ok(InnerInteger::I64(reader.read_i48::<LittleEndian>()?)),
8 => Ok(InnerInteger::I64(reader.read_i64::<LittleEndian>()?)),
16 => Ok(InnerInteger::I128(reader.read_i128::<LittleEndian>()?)),
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()?)),
Expand All @@ -944,9 +943,9 @@ impl Integer {
6 => Ok(InnerInteger::U64(reader.read_u48::<LittleEndian>()?)),
8 => Ok(InnerInteger::U64(reader.read_u64::<LittleEndian>()?)),
16 => Ok(InnerInteger::U128(reader.read_u128::<LittleEndian>()?)),
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)
}
Expand Down Expand Up @@ -1262,10 +1261,10 @@ impl Float {
2 => Ok(Self::from(read_f16(reader)?)),
4 => Ok(Self::from(reader.read_f32::<LittleEndian>()?)),
8 => Ok(Self::from(reader.read_f64::<LittleEndian>()?)),
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))
}
}
}
Expand Down

0 comments on commit b67e220

Please sign in to comment.