diff --git a/serde/src/de/impls.rs b/serde/src/de/impls.rs index e9631480..c1f3dad9 100644 --- a/serde/src/de/impls.rs +++ b/serde/src/de/impls.rs @@ -1580,6 +1580,24 @@ impl<'de> Visitor<'de> for PathBufVisitor { { Ok(From::from(v)) } + + fn visit_bytes(self, v: &[u8]) -> Result + where + E: Error, + { + str::from_utf8(v) + .map(From::from) + .map_err(|_| Error::invalid_value(Unexpected::Bytes(v), &self)) + } + + fn visit_byte_buf(self, v: Vec) -> Result + where + E: Error, + { + String::from_utf8(v) + .map(From::from) + .map_err(|e| Error::invalid_value(Unexpected::Bytes(&e.into_bytes()), &self)) + } } #[cfg(feature = "std")] diff --git a/test_suite/tests/test_de.rs b/test_suite/tests/test_de.rs index 16628efd..97ca875c 100644 --- a/test_suite/tests/test_de.rs +++ b/test_suite/tests/test_de.rs @@ -889,11 +889,23 @@ declare_tests! { Path::new("/usr/local/lib") => &[ Token::BorrowedStr("/usr/local/lib"), ], + Path::new("/usr/local/lib") => &[ + Token::BorrowedBytes(b"/usr/local/lib"), + ], } test_path_buf { + PathBuf::from("/usr/local/lib") => &[ + Token::Str("/usr/local/lib"), + ], PathBuf::from("/usr/local/lib") => &[ Token::String("/usr/local/lib"), ], + PathBuf::from("/usr/local/lib") => &[ + Token::Bytes(b"/usr/local/lib"), + ], + PathBuf::from("/usr/local/lib") => &[ + Token::ByteBuf(b"/usr/local/lib"), + ], } test_cstring { CString::new("abc").unwrap() => &[