diff --git a/src/bytes.rs b/src/bytes.rs index 3160bbdd4738adac3f26d015604ad4200c4712bf..5ff0a70908b31157f8e218e0e3854d33232ebc50 100644 --- a/src/bytes.rs +++ b/src/bytes.rs @@ -1,6 +1,7 @@ use {IntoBuf, BufMut}; -use std::{cmp, fmt, mem, ops, slice, ptr}; +use std::{cmp, fmt, mem, hash, ops, slice, ptr}; +use std::borrow::Borrow; use std::cell::{Cell, UnsafeCell}; use std::io::Cursor; use std::sync::Arc; @@ -522,6 +523,19 @@ impl fmt::Debug for Bytes { } } +impl hash::Hash for Bytes { + fn hash<H>(&self, state: &mut H) where H: hash::Hasher { + let s: &[u8] = self.as_ref(); + s.hash(state); + } +} + +impl Borrow<[u8]> for Bytes { + fn borrow(&self) -> &[u8] { + self.as_ref() + } +} + unsafe impl Sync for Bytes {} /* @@ -1003,6 +1017,19 @@ impl fmt::Debug for BytesMut { } } +impl hash::Hash for BytesMut { + fn hash<H>(&self, state: &mut H) where H: hash::Hasher { + let s: &[u8] = self.as_ref(); + s.hash(state); + } +} + +impl Borrow<[u8]> for BytesMut { + fn borrow(&self) -> &[u8] { + self.as_ref() + } +} + impl fmt::Write for BytesMut { fn write_str(&mut self, s: &str) -> fmt::Result { BufMut::put(self, s);