Skip to content

Commit

Permalink
feat:experience the Bytes lib
Browse files Browse the repository at this point in the history
  • Loading branch information
okqin committed Jul 30, 2024
1 parent c9c4cb4 commit a3cf3cf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
23 changes: 23 additions & 0 deletions examples/bytes.rs
Original file line number Diff line number Diff line change
@@ -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(())
}

0 comments on commit a3cf3cf

Please sign in to comment.