Skip to content

Commit

Permalink
feat(packet): implement From<Fulfill/Reject> for bytes05::BytesMut
Browse files Browse the repository at this point in the history
ILP-Packet is built using Bytes 0.4. The Futures 0.3 ecosystem's HTTP crates use Bytes 0.5.
Porting this crate to use Bytes 0.5 is non-trivial due to significant breaking changes in the
Bytes API:

tokio-rs/bytes#350
tokio-rs/bytes#288
  • Loading branch information
gakonst committed Jan 15, 2020
1 parent 7485916 commit 9d63807
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/interledger-packet/Cargo.toml
Expand Up @@ -9,6 +9,7 @@ repository = "https://github.com/interledger-rs/interledger-rs"

[dependencies]
byteorder = { version = "1.3.2", default-features = false }
bytes05 = { package = "bytes", version = "0.5", default-features = false, features = ["serde"] }
bytes = { version = "0.4.12", default-features = false, features = ["serde"] }
chrono = { version = "0.4.9", default-features = false }
hex = { version = "0.4.0", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion crates/interledger-packet/src/errors.rs
Expand Up @@ -41,7 +41,7 @@ quick_error! {
description(descr)
display("Invalid Packet {}", descr)
}
Other(err: Box<dyn std::error::Error>) {
Other(err: Box<dyn std::error::Error + Send>) {
cause(&**err)
description(err.description())
display("Error {}", err.description())
Expand Down
18 changes: 18 additions & 0 deletions crates/interledger-packet/src/packet.rs
Expand Up @@ -359,6 +359,15 @@ impl From<Fulfill> for BytesMut {
}
}

impl From<Fulfill> for bytes05::BytesMut {
fn from(fulfill: Fulfill) -> Self {
// bytes 0.4
let b = fulfill.buffer.as_ref();
// convert to Bytes05
bytes05::BytesMut::from(b)
}
}

impl fmt::Debug for Fulfill {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter
Expand Down Expand Up @@ -481,6 +490,15 @@ impl From<Reject> for BytesMut {
}
}

impl From<Reject> for bytes05::BytesMut {
fn from(reject: Reject) -> Self {
// bytes 0.4
let b = reject.buffer.as_ref();
// convert to Bytes05
bytes05::BytesMut::from(b)
}
}

impl fmt::Debug for Reject {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter
Expand Down

0 comments on commit 9d63807

Please sign in to comment.