Deserialize Box<Path> through PathBuf::into_boxed_path

Including Rc<Path> et al.

Fixes https://github.com/serde-rs/serde/issues/1633
This commit is contained in:
Jan Alexander Steffens (heftig) 2019-10-22 22:29:30 +02:00
parent 42990d8264
commit b8772a1e40
No known key found for this signature in database
GPG Key ID: A5E9288C4FA415FA
3 changed files with 19 additions and 1 deletions

View File

@ -29,8 +29,9 @@ fn main() {
println!("cargo:rustc-cfg=core_reverse");
}
// CString::into_boxed_c_str stabilized in Rust 1.20:
// CString::into_boxed_c_str and PathBuf::into_boxed_path stabilized in Rust 1.20:
// https://doc.rust-lang.org/std/ffi/struct.CString.html#method.into_boxed_c_str
// https://doc.rust-lang.org/std/path/struct.PathBuf.html#method.into_boxed_path
if minor >= 20 {
println!("cargo:rustc-cfg=de_boxed_c_str");
}

View File

@ -1610,6 +1610,9 @@ impl<'de> Deserialize<'de> for PathBuf {
}
}
#[cfg(all(feature = "std", de_boxed_c_str))]
forwarded_impl!((), Box<Path>, PathBuf::into_boxed_path);
////////////////////////////////////////////////////////////////////////////////
// If this were outside of the serde crate, it would just use:

View File

@ -907,6 +907,20 @@ declare_tests! {
Token::ByteBuf(b"/usr/local/lib"),
],
}
test_boxed_path {
PathBuf::from("/usr/local/lib").into_boxed_path() => &[
Token::Str("/usr/local/lib"),
],
PathBuf::from("/usr/local/lib").into_boxed_path() => &[
Token::String("/usr/local/lib"),
],
PathBuf::from("/usr/local/lib").into_boxed_path() => &[
Token::Bytes(b"/usr/local/lib"),
],
PathBuf::from("/usr/local/lib").into_boxed_path() => &[
Token::ByteBuf(b"/usr/local/lib"),
],
}
test_cstring {
CString::new("abc").unwrap() => &[
Token::Bytes(b"abc"),