Skip to content

Commit

Permalink
Add KeyCode encoding module.
Browse files Browse the repository at this point in the history
Same format, but this uses Serde for (de)serialization.
  • Loading branch information
erikgrinaker committed Sep 3, 2023
1 parent b74ff17 commit 99c9a64
Show file tree
Hide file tree
Showing 5 changed files with 787 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors = ["Erik Grinaker <[email protected]>"]
edition = "2021"
default-run = "toydb"

[lib]
doctest = false

[dependencies]
bincode = "~1.3.3"
clap = { version = "~4.3.21", features = ["cargo"] }
Expand All @@ -14,6 +17,7 @@ derivative = "~2.2.0"
fs4 = "0.6.6"
futures = "~0.3.15"
futures-util = "~0.3.15"
hex = "0.4.3"
lazy_static = "~1.4.0"
log = "~0.4.14"
names = "~0.14.0"
Expand All @@ -22,6 +26,7 @@ regex = "1.5.4"
rustyline = "~12.0.0"
rustyline-derive = "0.9.0"
serde = "~1.0.126"
serde_bytes = "0.11.12"
serde_derive = "~1.0.126"
simplelog = "~0.12.1"
tokio = { version = "~1.31.0", features = [
Expand All @@ -40,6 +45,7 @@ uuid = { version = "~1.4.1", features = ["v4"] }

[dev-dependencies]
goldenfile = "~1.5.2"
paste = "1.0.14"
pretty_assertions = "~1.4.0"
serial_test = "~2.0.0"
tempdir = "~0.3.7"
Expand Down
24 changes: 24 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ impl Display for Error {
}
}

impl serde::ser::Error for Error {
fn custom<T: Display>(msg: T) -> Self {
Error::Internal(msg.to_string())
}
}

impl serde::de::Error for Error {
fn custom<T: Display>(msg: T) -> Self {
Error::Internal(msg.to_string())
}
}

impl From<Box<bincode::ErrorKind>> for Error {
fn from(err: Box<bincode::ErrorKind>) -> Self {
Error::Internal(err.to_string())
Expand All @@ -43,6 +55,12 @@ impl From<config::ConfigError> for Error {
}
}

impl From<hex::FromHexError> for Error {
fn from(err: hex::FromHexError) -> Self {
Error::Internal(err.to_string())
}
}

impl From<log::ParseLevelError> for Error {
fn from(err: log::ParseLevelError) -> Self {
Error::Config(err.to_string())
Expand Down Expand Up @@ -73,6 +91,12 @@ impl From<std::array::TryFromSliceError> for Error {
}
}

impl From<std::num::TryFromIntError> for Error {
fn from(err: std::num::TryFromIntError) -> Self {
Error::Value(err.to_string())
}
}

impl From<std::io::Error> for Error {
fn from(err: std::io::Error) -> Self {
Error::Internal(err.to_string())
Expand Down
Loading

0 comments on commit 99c9a64

Please sign in to comment.