-
Notifications
You must be signed in to change notification settings - Fork 313
Closed
Labels
Description
Hi,
I created a BytesBuf with some data and removed the leading n bytes with advance(n). After some more computations I converted the result to an immutable Bytes value. My expectation was that the content of the BytesMut and Bytes would be identical. Instead the Bytes still contained the discared bytes.
Example program:
use bytes::{BytesMut, Buf, BufMut};
fn main() {
let mut x = BytesMut::new();
x.put(&b"hello"[..]);
let mut y = BytesMut::new();
y.put(&b"hello"[..]);
y.advance(2);
println!("{:?} {:?}", x, y); // b"hello" b"llo"
assert_ne!(x, y);
assert_ne!(&x[..], &y[..]);
let x1 = x.freeze();
let y1 = y.freeze();
println!("{:?} {:?}", x1, y1); // b"hello" b"hello"
// expected: b"hello" b"llo"
assert_eq!(x1, y1);
assert_eq!(&x1[..], &y1[..]);
}As a work-around I use split_to instead of advance and ignore the return value.
stepancheg