diff --git a/Cargo.lock b/Cargo.lock index 2c37681..6231aff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -233,9 +233,9 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytes" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +checksum = "a12916984aab3fa6e39d655a33e09c0071eb36d6ab3aea5c2d78551f1df6d952" [[package]] name = "cc" @@ -399,6 +399,7 @@ dependencies = [ "anyhow", "axum 0.7.5", "base64 0.22.1", + "bytes", "chrono", "derive_builder", "derive_more", diff --git a/Cargo.toml b/Cargo.toml index a5fe1e8..dbf3324 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } [dev-dependencies] axum = { version = "0.7.5", features = ["http2", "query", "tracing"] } base64 = "0.22.1" +bytes = "1.6.1" chrono = "0.4.38" derive_builder = "0.20.0" derive_more = { version = "=1.0.0-beta.6", features = ["full"] } diff --git a/examples/bytes.rs b/examples/bytes.rs new file mode 100644 index 0000000..a4c540c --- /dev/null +++ b/examples/bytes.rs @@ -0,0 +1,23 @@ +use anyhow::Result; +use bytes::{BufMut, BytesMut}; + +fn main() -> Result<()> { + let mut buf = BytesMut::with_capacity(1024); + buf.extend_from_slice(b"Hello World\n"); + buf.put(&b"goodbye world\n"[..]); + buf.put_i64(0x0102030405060708); + + println!("{:?}", buf); + + let a = buf.split(); + println!("{:?}", a); + + let mut b = a.freeze(); + let c = b.split_to(12); + + println!("{:?}", b); + println!("{:?}", c); + println!("{:?}", buf); + + Ok(()) +}