From 1ffe96f00e5d0197212f78ec42612eef83f03b6f Mon Sep 17 00:00:00 2001 From: Luca Cavallin Date: Thu, 21 Dec 2023 23:42:15 +0100 Subject: [PATCH] remove GenericError from buffer --- Cargo.toml | 1 - README.md | 4 +--- src/buffer.rs | 13 +++---------- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bec2b15..c7fd32a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bytes = "1.5.0" clap = { version = "4.3.19", features = ["derive"] } log = "0.4.19" rand = "0.8.5" diff --git a/README.md b/README.md index 9e36226..7252a32 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,5 @@ $ make query [hostname=example.com] ## Improvements -- Use [tokio-rs/bytes](https://github.com/tokio-rs/bytes) for handling buffers. -- Replace `BufferError::GenericError(String)` with `#[error("I/O error: {0}")] IoError(#[from] std::io::Error)` +- Use [tokio-rs/bytes](https://github.com/tokio-rs/bytes) for handling buffers and `bitvec` for bit manipulation. - Async/await with tokio.rs (`header.rs` and `packet.rs` could use [tokio_util::codec](https://docs.rs/tokio-util/latest/tokio_util/codec/index.html)) -- Consider using crate `bitvec` for bit manipulation. diff --git a/src/buffer.rs b/src/buffer.rs index 3760c98..1e18c1c 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -1,5 +1,5 @@ /// `BufferError` is an enum that represents the various errors that can occur -#[derive(thiserror::Error, Debug, Clone)] +#[derive(thiserror::Error, Debug)] pub enum BufferError { #[error("End of buffer")] EndOfBuffer, @@ -7,15 +7,8 @@ pub enum BufferError { JumpsLimitExceeded(i32), #[error("Single label exceeds 63 characters of length")] LabelTooLong, - #[error("Generic error: {0}")] - GenericError(String), -} - -/// Implement the From trait for `BufferError`, so that we can use the ? operator -impl From for BufferError { - fn from(e: std::io::Error) -> Self { - BufferError::GenericError(e.to_string()) - } + #[error("I/O error: {0}")] + IoError(#[from] std::io::Error), } /// The `Buffer` struct is used to hold the contents of a DNS packet as a byte buffer,