feat: bytes

This commit is contained in:
2022-03-25 23:20:23 +08:00
parent f104c9dec9
commit 2b3e2a7c87

View File

@@ -1,4 +1,5 @@
use bytes::{BytesMut, BufMut}; use std::io::Read;
use bytes::{BytesMut, BufMut, Buf};
fn main() { fn main() {
let mut buf = BytesMut::new(); let mut buf = BytesMut::new();
@@ -15,4 +16,11 @@ fn main() {
println!("{:x?}", &buf2[..]); println!("{:x?}", &buf2[..]);
buf2.resize(8, 0x00); buf2.resize(8, 0x00);
println!("{:x?}", &buf2[..]); println!("{:x?}", &buf2[..]);
let mut buf3 = BytesMut::with_capacity(16);
buf3.put_slice(b"hello world");
let mut reader = buf3.reader();
let mut vec = vec![];
let len = reader.read_to_end(&mut vec);
println!("Len: {:?} -> {:x?}", len, vec);
} }