Deserialize PathBuf from bytes

&Path already allows this. Also complete the tests for Path/PathBuf.
This commit is contained in:
Jan Alexander Steffens (heftig)
2019-10-22 22:28:21 +02:00
parent cf31418555
commit 42990d8264
2 changed files with 30 additions and 0 deletions
+18
View File
@@ -1580,6 +1580,24 @@ impl<'de> Visitor<'de> for PathBufVisitor {
{
Ok(From::from(v))
}
fn visit_bytes<E>(self, v: &[u8]) -> Result<Self::Value, E>
where
E: Error,
{
str::from_utf8(v)
.map(From::from)
.map_err(|_| Error::invalid_value(Unexpected::Bytes(v), &self))
}
fn visit_byte_buf<E>(self, v: Vec<u8>) -> Result<Self::Value, E>
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")]