mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-27 00:00:17 +02:00
Add more conversion impls
This commit is contained in:
+14
-1
@@ -1,4 +1,4 @@
|
|||||||
use {Buf, BufMut, BytesMut};
|
use {Buf, BufMut, Bytes, BytesMut};
|
||||||
|
|
||||||
use std::{cmp, fmt};
|
use std::{cmp, fmt};
|
||||||
|
|
||||||
@@ -186,6 +186,19 @@ impl BufMut for ByteBuf {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<ByteBuf> for Bytes {
|
||||||
|
fn from(src: ByteBuf) -> Bytes {
|
||||||
|
let bytes = BytesMut::from(src);
|
||||||
|
bytes.freeze()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ByteBuf> for BytesMut {
|
||||||
|
fn from(src: ByteBuf) -> BytesMut {
|
||||||
|
src.mem
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl fmt::Debug for ByteBuf {
|
impl fmt::Debug for ByteBuf {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
self.bytes().fmt(fmt)
|
self.bytes().fmt(fmt)
|
||||||
|
|||||||
@@ -166,6 +166,12 @@ impl ops::Deref for Bytes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<BytesMut> for Bytes {
|
||||||
|
fn from(src: BytesMut) -> Bytes {
|
||||||
|
src.freeze()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<Vec<u8>> for Bytes {
|
impl From<Vec<u8>> for Bytes {
|
||||||
fn from(src: Vec<u8>) -> Bytes {
|
fn from(src: Vec<u8>) -> Bytes {
|
||||||
BytesMut::from(src).freeze()
|
BytesMut::from(src).freeze()
|
||||||
|
|||||||
Reference in New Issue
Block a user