Merge pull request #652 from serde-rs/bbstr

Support deserializing ByteBuf from string
This commit is contained in:
Oliver Schneider
2016-12-25 01:09:15 +01:00
committed by GitHub
3 changed files with 55 additions and 157 deletions
+14 -2
View File
@@ -84,7 +84,7 @@ mod bytebuf {
use de;
#[cfg(feature = "collections")]
use collections::Vec;
use collections::{String, Vec};
/// `ByteBuf` wraps a `Vec<u8>` and serializes as a byte array.
#[derive(Clone, Default, Eq, Hash, PartialEq, PartialOrd, Ord)]
@@ -208,7 +208,7 @@ mod bytebuf {
fn visit_bytes<E>(&mut self, v: &[u8]) -> Result<ByteBuf, E>
where E: de::Error,
{
self.visit_byte_buf(v.to_vec())
Ok(ByteBuf::from(v))
}
#[inline]
@@ -217,6 +217,18 @@ mod bytebuf {
{
Ok(ByteBuf::from(v))
}
fn visit_str<E>(&mut self, v: &str) -> Result<ByteBuf, E>
where E: de::Error,
{
Ok(ByteBuf::from(v))
}
fn visit_string<E>(&mut self, v: String) -> Result<ByteBuf, E>
where E: de::Error,
{
Ok(ByteBuf::from(v))
}
}
impl de::Deserialize for ByteBuf {