Skip to content

Commit b8772a1

Browse files
committed
Deserialize Box<Path> through PathBuf::into_boxed_path
Including Rc<Path> et al. Fixes #1633
1 parent 42990d8 commit b8772a1

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

serde/build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ fn main() {
2929
println!("cargo:rustc-cfg=core_reverse");
3030
}
3131

32-
// CString::into_boxed_c_str stabilized in Rust 1.20:
32+
// CString::into_boxed_c_str and PathBuf::into_boxed_path stabilized in Rust 1.20:
3333
// https://doc.rust-lang.org/std/ffi/struct.CString.html#method.into_boxed_c_str
34+
// https://doc.rust-lang.org/std/path/struct.PathBuf.html#method.into_boxed_path
3435
if minor >= 20 {
3536
println!("cargo:rustc-cfg=de_boxed_c_str");
3637
}

serde/src/de/impls.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,6 +1610,9 @@ impl<'de> Deserialize<'de> for PathBuf {
16101610
}
16111611
}
16121612

1613+
#[cfg(all(feature = "std", de_boxed_c_str))]
1614+
forwarded_impl!((), Box<Path>, PathBuf::into_boxed_path);
1615+
16131616
////////////////////////////////////////////////////////////////////////////////
16141617

16151618
// If this were outside of the serde crate, it would just use:

test_suite/tests/test_de.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,20 @@ declare_tests! {
907907
Token::ByteBuf(b"/usr/local/lib"),
908908
],
909909
}
910+
test_boxed_path {
911+
PathBuf::from("/usr/local/lib").into_boxed_path() => &[
912+
Token::Str("/usr/local/lib"),
913+
],
914+
PathBuf::from("/usr/local/lib").into_boxed_path() => &[
915+
Token::String("/usr/local/lib"),
916+
],
917+
PathBuf::from("/usr/local/lib").into_boxed_path() => &[
918+
Token::Bytes(b"/usr/local/lib"),
919+
],
920+
PathBuf::from("/usr/local/lib").into_boxed_path() => &[
921+
Token::ByteBuf(b"/usr/local/lib"),
922+
],
923+
}
910924
test_cstring {
911925
CString::new("abc").unwrap() => &[
912926
Token::Bytes(b"abc"),

0 commit comments

Comments
 (0)