mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-27 00:00:12 +02:00
Merge pull request #168 from Byron/master
Implement PartialEq for EasyBuf
This commit is contained in:
+30
-1
@@ -17,13 +17,19 @@ const INITIAL_CAPACITY: usize = 8 * 1024;
|
|||||||
/// be handed out efficiently, each with a `'static` lifetime which keeps the
|
/// be handed out efficiently, each with a `'static` lifetime which keeps the
|
||||||
/// data alive. The buffer also supports mutation but may require bytes to be
|
/// data alive. The buffer also supports mutation but may require bytes to be
|
||||||
/// copied to complete the operation.
|
/// copied to complete the operation.
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Eq)]
|
||||||
pub struct EasyBuf {
|
pub struct EasyBuf {
|
||||||
buf: Arc<Vec<u8>>,
|
buf: Arc<Vec<u8>>,
|
||||||
start: usize,
|
start: usize,
|
||||||
end: usize,
|
end: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PartialEq for EasyBuf {
|
||||||
|
fn eq(&self, other: &EasyBuf) -> bool {
|
||||||
|
self.as_slice() == other.as_slice()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// An RAII object returned from `get_mut` which provides mutable access to the
|
/// An RAII object returned from `get_mut` which provides mutable access to the
|
||||||
/// underlying `Vec<u8>`.
|
/// underlying `Vec<u8>`.
|
||||||
pub struct EasyBufMut<'a> {
|
pub struct EasyBufMut<'a> {
|
||||||
@@ -531,4 +537,27 @@ mod tests {
|
|||||||
assert_ne!(original_pointer, new_pointer, "A new vec should be allocated");
|
assert_ne!(original_pointer, new_pointer, "A new vec should be allocated");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn easybuf_equality_same_underlying_vec() {
|
||||||
|
let mut buf: EasyBuf = (0u8..10).collect::<Vec<_>>().into();
|
||||||
|
assert_eq!(buf, buf);
|
||||||
|
let other = buf.drain_to(5);
|
||||||
|
assert_ne!(buf, other);
|
||||||
|
|
||||||
|
let buf: EasyBuf = (0u8..5).collect::<Vec<_>>().into();
|
||||||
|
assert_eq!(buf, other);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn easybuf_equality_different_underlying_vec() {
|
||||||
|
let mut buf: EasyBuf = (0u8..10).collect::<Vec<_>>().into();
|
||||||
|
let mut other: EasyBuf = (0u8..10).collect::<Vec<_>>().into();
|
||||||
|
assert_eq!(buf, other);
|
||||||
|
|
||||||
|
buf = buf.drain_to(5);
|
||||||
|
assert_ne!(buf, other);
|
||||||
|
|
||||||
|
other = other.drain_to(5);
|
||||||
|
assert_eq!(buf, other);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user