Add an example to the Configure trait

This commit is contained in:
Markus Westerlind
2017-11-03 16:12:43 +01:00
parent 1b9a096fa7
commit aad7a7987f
10 changed files with 157 additions and 186 deletions
+5 -17
View File
@@ -16,7 +16,6 @@ use token::Token;
#[derive(Debug)]
pub struct Deserializer<'de> {
tokens: &'de [Token],
is_human_readable: Option<bool>,
}
macro_rules! assert_next_token {
@@ -49,13 +48,7 @@ macro_rules! end_of_tokens {
impl<'de> Deserializer<'de> {
pub fn new(tokens: &'de [Token]) -> Self {
Deserializer::readable(tokens, None)
}
// Not public API
#[doc(hidden)]
pub fn readable(tokens: &'de [Token], is_human_readable: Option<bool>) -> Self {
Deserializer { tokens: tokens, is_human_readable: is_human_readable }
Deserializer { tokens: tokens }
}
fn peek_token_opt(&self) -> Option<Token> {
@@ -373,15 +366,10 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> {
}
fn is_human_readable(&self) -> bool {
match self.is_human_readable {
Some(is) => is,
None => {
panic!("There is no serde_test API currently for testing types \
that have different human-readable and compact \
representation. See \
https://github.com/serde-rs/serde/issues/1065.");
}
}
panic!(
"Types which have different human-readable and compact representations\
must explicitly mark their test cases with `serde_test::Configure`"
);
}
}