Skip to content

Commit

Permalink
remove GenericError from buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
lucavallin committed Dec 21, 2023
1 parent f494f74 commit 1ffe96f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 14 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
13 changes: 3 additions & 10 deletions src/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
/// `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,
#[error("Limit of {0} jumps exceeded")]
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<std::io::Error> 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,
Expand Down

0 comments on commit 1ffe96f

Please sign in to comment.