From 4507eaec5b0d136d65ac823424e007c3d79a36bf Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Thu, 28 Jan 2016 09:45:38 -0800 Subject: [PATCH] Use deserializer.visit_string for PathBuf --- serde/src/de/impls.rs | 2 +- serde_tests/tests/test_de.rs | 6 ++++++ serde_tests/tests/test_ser.rs | 11 +++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/serde/src/de/impls.rs b/serde/src/de/impls.rs index ef696484..2a8fc00f 100644 --- a/serde/src/de/impls.rs +++ b/serde/src/de/impls.rs @@ -762,7 +762,7 @@ impl Deserialize for path::PathBuf { fn deserialize(deserializer: &mut D) -> Result where D: Deserializer, { - deserializer.visit(PathBufVisitor) + deserializer.visit_string(PathBufVisitor) } } diff --git a/serde_tests/tests/test_de.rs b/serde_tests/tests/test_de.rs index f818b105..7663619e 100644 --- a/serde_tests/tests/test_de.rs +++ b/serde_tests/tests/test_de.rs @@ -1,4 +1,5 @@ use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; +use std::path::PathBuf; use num::FromPrimitive; use num::bigint::{BigInt, BigUint}; @@ -589,4 +590,9 @@ declare_tests! { Token::SeqEnd, ], } + test_path_buf { + PathBuf::from("/usr/local/lib") => vec![ + Token::String("/usr/local/lib".to_owned()), + ], + } } diff --git a/serde_tests/tests/test_ser.rs b/serde_tests/tests/test_ser.rs index a5947508..7fbae4e4 100644 --- a/serde_tests/tests/test_ser.rs +++ b/serde_tests/tests/test_ser.rs @@ -1,4 +1,5 @@ use std::collections::BTreeMap; +use std::path::{Path, PathBuf}; use num::FromPrimitive; use num::bigint::{BigInt, BigUint}; @@ -293,4 +294,14 @@ declare_ser_tests! { Token::SeqEnd, ], } + test_path { + Path::new("/usr/local/lib") => &[ + Token::Str("/usr/local/lib"), + ], + } + test_path_buf { + PathBuf::from("/usr/local/lib") => &[ + Token::Str("/usr/local/lib"), + ], + } }