mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-09-02 00:00:16 +02:00
Implement Hash and Borrow for Bytes / BytesMut
This commit is contained in:
+28
-1
@@ -1,6 +1,7 @@
|
|||||||
use {IntoBuf, BufMut};
|
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::cell::{Cell, UnsafeCell};
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
use std::sync::Arc;
|
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 {}
|
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 {
|
impl fmt::Write for BytesMut {
|
||||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||||
BufMut::put(self, s);
|
BufMut::put(self, s);
|
||||||
|
|||||||
Reference in New Issue
Block a user