Implement impls for std::path::Path{,Buf}

Closes #28.
This commit is contained in:
Erick Tryzelaar
2015-03-05 22:39:35 -08:00
parent 776e6448a2
commit 6b7aa269b8
3 changed files with 56 additions and 13 deletions
+30 -1
View File
@@ -1,7 +1,8 @@
use std::marker::PhantomData;
use std::collections::{HashMap, BTreeMap};
use std::hash::Hash;
use std::marker::PhantomData;
use std::num::FromPrimitive;
use std::path;
use std::str;
///////////////////////////////////////////////////////////////////////////////
@@ -788,3 +789,31 @@ impl<
deserializer.visit(BTreeMapVisitor::new())
}
}
///////////////////////////////////////////////////////////////////////////////
struct PathBufVisitor;
impl Visitor for PathBufVisitor {
type Value = path::PathBuf;
fn visit_str<E>(&mut self, v: &str) -> Result<path::PathBuf, E>
where E: Error,
{
Ok(path::PathBuf::new(&v))
}
fn visit_string<E>(&mut self, v: String) -> Result<path::PathBuf, E>
where E: Error,
{
self.visit_str(&v)
}
}
impl Deserialize for path::PathBuf {
fn deserialize<D>(deserializer: &mut D) -> Result<path::PathBuf, D::Error>
where D: Deserializer,
{
deserializer.visit(PathBufVisitor)
}
}