From 54dcd3a015bb61eb7f297da69f2ad978425c488d Mon Sep 17 00:00:00 2001 From: Martin Hoffmann Date: Sat, 18 Feb 2017 20:30:01 +0100 Subject: [PATCH] Add PartialOrd and Ord to EasyBuf, generalize PartialEq. --- src/io/frame.rs | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/io/frame.rs b/src/io/frame.rs index 288249ac0..ea82f67af 100644 --- a/src/io/frame.rs +++ b/src/io/frame.rs @@ -1,5 +1,6 @@ use std::fmt; use std::io; +use std::hash; use std::mem; use std::cmp; use std::ops::{Deref, DerefMut}; @@ -24,12 +25,6 @@ pub struct EasyBuf { 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 /// underlying `Vec`. pub struct EasyBufMut<'a> { @@ -201,6 +196,30 @@ impl From> for EasyBuf { } } +impl> PartialEq 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> PartialOrd for EasyBuf { + fn partial_cmp(&self, other: &T) -> Option { + self.as_slice().partial_cmp(other.as_ref()) + } +} + +impl hash::Hash for EasyBuf { + fn hash(&self, state: &mut H) { + self.as_slice().hash(state) + } +} + impl<'a> Drop for EasyBufMut<'a> { fn drop(&mut self) { *self.end = self.buf.len();