mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-07 00:00:08 +02:00
Add PartialOrd and Ord to EasyBuf, generalize PartialEq.
This commit is contained in:
+25
-6
@@ -1,5 +1,6 @@
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
use std::hash;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
@@ -24,12 +25,6 @@ pub struct EasyBuf {
|
|||||||
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> {
|
||||||
@@ -201,6 +196,30 @@ impl From<Vec<u8>> for EasyBuf {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: AsRef<[u8]>> PartialEq<T> for EasyBuf {
|
||||||
|
fn eq(&self, other: &T) -> bool {
|
||||||
|
self.as_slice().eq(other.as_ref())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Ord for EasyBuf {
|
||||||
|
fn cmp(&self, other: &Self) -> cmp::Ordering {
|
||||||
|
self.as_slice().cmp(other.as_slice())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: AsRef<[u8]>> PartialOrd<T> for EasyBuf {
|
||||||
|
fn partial_cmp(&self, other: &T) -> Option<cmp::Ordering> {
|
||||||
|
self.as_slice().partial_cmp(other.as_ref())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl hash::Hash for EasyBuf {
|
||||||
|
fn hash<H: hash::Hasher>(&self, state: &mut H) {
|
||||||
|
self.as_slice().hash(state)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> Drop for EasyBufMut<'a> {
|
impl<'a> Drop for EasyBufMut<'a> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
*self.end = self.buf.len();
|
*self.end = self.buf.len();
|
||||||
|
|||||||
Reference in New Issue
Block a user