Merge pull request #290 from dtolnay/boxslice

fix(impls): Deserialize impl for Box<[T]>
This commit is contained in:
Erick Tryzelaar 2016-04-19 12:21:11 -05:00
commit 8cce6ecf15
3 changed files with 39 additions and 0 deletions

View File

@ -881,6 +881,15 @@ impl<T: Deserialize> Deserialize for Box<T> {
}
}
impl<T: Deserialize> Deserialize for Box<[T]> {
fn deserialize<D>(deserializer: &mut D) -> Result<Box<[T]>, D::Error>
where D: Deserializer,
{
let v: Vec<T> = try!(Deserialize::deserialize(deserializer));
Ok(v.into_boxed_slice())
}
}
impl<T: Deserialize> Deserialize for Arc<T> {
fn deserialize<D>(deserializer: &mut D) -> Result<Arc<T>, D::Error>
where D: Deserializer,

View File

@ -664,6 +664,21 @@ declare_tests! {
Token::Unit,
],
}
test_box {
Box::new(0i32) => vec![Token::I32(0)],
}
test_boxed_slice {
Box::new([0, 1, 2]) => vec![
Token::SeqStart(Some(3)),
Token::SeqSep,
Token::I32(0),
Token::SeqSep,
Token::I32(1),
Token::SeqSep,
Token::I32(2),
Token::SeqEnd,
],
}
test_net_ipv4addr {
"1.2.3.4".parse::<net::Ipv4Addr>().unwrap() => vec![Token::Str("1.2.3.4")],
}

View File

@ -262,6 +262,21 @@ declare_ser_tests! {
Token::EnumMapEnd,
],
}
test_box {
Box::new(0i32) => &[Token::I32(0)],
}
test_boxed_slice {
Box::new([0, 1, 2]) => &[
Token::SeqArrayStart(3),
Token::SeqSep,
Token::I32(0),
Token::SeqSep,
Token::I32(1),
Token::SeqSep,
Token::I32(2),
Token::SeqEnd,
],
}
test_net_ipv4addr {
"1.2.3.4".parse::<net::Ipv4Addr>().unwrap() => &[Token::Str("1.2.3.4")],
}