diff --git a/serde/src/bytes.rs b/serde/src/bytes.rs index 67f8ce85..12e42e75 100644 --- a/serde/src/bytes.rs +++ b/serde/src/bytes.rs @@ -19,6 +19,15 @@ pub struct Bytes<'a> { bytes: &'a [u8], } +impl<'a> Bytes<'a> { + /// Wrap an existing `&[u8]`. + pub fn new(bytes: &'a [u8]) -> Self { + Bytes { + bytes: bytes, + } + } +} + impl<'a> fmt::Debug for Bytes<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(f.write_str("b\"")); @@ -101,6 +110,13 @@ mod bytebuf { bytes: Vec::with_capacity(cap) } } + + /// Wrap existing bytes in a `ByteBuf`. + pub fn from>>(bytes: T) -> Self { + ByteBuf { + bytes: bytes.into(), + } + } } impl fmt::Debug for ByteBuf {