From fa589fb8aac4f7bfd753000ff6dec5165882d10e Mon Sep 17 00:00:00 2001 From: Nikita Pekin Date: Sat, 17 Dec 2016 18:24:21 -0500 Subject: [PATCH 1/6] tests: add test for `Error` struct deserialization. Add test for `Error` struct deserialization. --- src/model.rs | 6 ++++++ tests/sample-data/error.xml | 4 ++++ 2 files changed, 10 insertions(+) create mode 100644 tests/sample-data/error.xml diff --git a/src/model.rs b/src/model.rs index 9466f1a..62d03c7 100644 --- a/src/model.rs +++ b/src/model.rs @@ -37,6 +37,7 @@ mod tests { Definitions, DidYouMean, DidYouMeans, + Error, Img, Infos, LanguageMsg, @@ -193,4 +194,9 @@ mod tests { fn test_infos_deserializer() { from_str::(&read_sample_data_from_path("tests/sample-data/infos.xml")).unwrap(); } + + #[test] + fn test_error_deserializer() { + from_str::(&read_sample_data_from_path("tests/sample-data/error.xml")).unwrap(); + } } diff --git a/tests/sample-data/error.xml b/tests/sample-data/error.xml new file mode 100644 index 0000000..01993b3 --- /dev/null +++ b/tests/sample-data/error.xml @@ -0,0 +1,4 @@ + + 2 + Appid missing + From b4f7524cb805b1815e49edb87cff23232d4ab870 Mon Sep 17 00:00:00 2001 From: Nikita Pekin Date: Sat, 17 Dec 2016 18:25:26 -0500 Subject: [PATCH 2/6] tests: add test for `QueryResult` with `Error` Add a test for a `QueryResult` response containing an `Error` struct. --- src/model.rs | 5 +++++ tests/sample-data/query_result-with-error.xml | 8 ++++++++ 2 files changed, 13 insertions(+) create mode 100644 tests/sample-data/query_result-with-error.xml diff --git a/src/model.rs b/src/model.rs index 62d03c7..2822721 100644 --- a/src/model.rs +++ b/src/model.rs @@ -74,6 +74,11 @@ mod tests { from_str::(&read_sample_data_from_path("tests/sample-data/query_result_7.xml")).unwrap(); } + #[test] + fn test_query_result_with_error_deserializer() { + from_str::(&read_sample_data_from_path("tests/sample-data/query_result-with-error.xml")).unwrap(); + } + #[test] fn test_notes_deserializer() { from_str::(&read_sample_data_from_path("tests/sample-data/notes.xml")).unwrap(); diff --git a/tests/sample-data/query_result-with-error.xml b/tests/sample-data/query_result-with-error.xml new file mode 100644 index 0000000..0b3fd93 --- /dev/null +++ b/tests/sample-data/query_result-with-error.xml @@ -0,0 +1,8 @@ + + + + 2 + Appid missing + + From 93f2f2fb59b53286fe292ab2167b4b45d3f905d3 Mon Sep 17 00:00:00 2001 From: Nikita Pekin Date: Sat, 17 Dec 2016 18:28:27 -0500 Subject: [PATCH 3/6] impr: rename `error` field to `error_flag` Rename `error` field to `error_flag` in `QueryResult` struct. BREAKING CHANGE: fields in the `QueryResult` struct have been renamed. To migrate, you need to rename any references to the `QueryResult` fields `error` to `error_flag`. --- src/model.in.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/model.in.rs b/src/model.in.rs index f8798db..3726315 100644 --- a/src/model.in.rs +++ b/src/model.in.rs @@ -5,7 +5,7 @@ pub struct QueryResult { // Attributes pub success: bool, - pub error: bool, + pub error_flag: bool, pub numpods: u32, pub version: String, // TODO: replace this with a better type. pub datatypes: String, // TODO: possibly replace this with an enum? From 468be31e34fd1c531190e2954670dfb314c12388 Mon Sep 17 00:00:00 2001 From: Nikita Pekin Date: Sat, 17 Dec 2016 18:37:03 -0500 Subject: [PATCH 4/6] fix: change `QueryResult` field types Modify the types for the `QueryResult` fields `version`, `timedoutpods`, `parsedtimeout`, `recalculate`, `id`, `server`, `related`, and `pod` from from `T` to `Option`. This is necessary to properly handle requests where this information is omitted (e.g. when an API error is returned). BREAKING CHANGE: types for various `QueryResult` fields have been wrapped in the `Option` type. To migrate, modify the types for the fields `version`, `timedoutpods`, `parsedtimeout`, `recalculate`, `id`, `server`, `related`, and `pod` from `T` to `Option`. --- src/model.in.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/model.in.rs b/src/model.in.rs index 3726315..83d3823 100644 --- a/src/model.in.rs +++ b/src/model.in.rs @@ -7,20 +7,20 @@ pub struct QueryResult { pub success: bool, pub error_flag: bool, pub numpods: u32, - pub version: String, // TODO: replace this with a better type. + pub version: Option, // TODO: replace this with a better type. pub datatypes: String, // TODO: possibly replace this with an enum? pub timing: f64, pub timedout: String, - pub timedoutpods: String, + pub timedoutpods: Option, pub parsetiming: f64, - pub parsetimedout: bool, - pub recalculate: String, - pub id: String, - //pub host: String, // FIXME - pub server: u32, - pub related: String, - - pub pod: Vec, + pub parsetimedout: Option, + pub recalculate: Option, + pub id: Option, + //pub host: Option, // FIXME + pub server: Option, + pub related: Option, + + pub pod: Option>, pub assumptions: Option, pub sources: Option, // TODO: find a way to parse errors. From d79ed2e06f1863073cf804ef4d243c1f8e5e8b22 Mon Sep 17 00:00:00 2001 From: Nikita Pekin Date: Sat, 17 Dec 2016 18:40:43 -0500 Subject: [PATCH 5/6] impr: add `error` field to `QueryResult` Adds the `error` field representing an optional `Error` struct instance to the `QueryResult` struct. Remove the derived deserializer for the `QueryResult` struct. Add a customized deserializer for the `QueryResult` struct, which is necessary to handle `QueryResult` deserialization properly, as it contains both an `error` attribute and an `error` element. --- src/model.in.rs | 1214 ++++++++++++++++++++++++++++++++++++++++++++++- src/model.rs | 1 + 2 files changed, 1210 insertions(+), 5 deletions(-) diff --git a/src/model.in.rs b/src/model.in.rs index 83d3823..4470e4e 100644 --- a/src/model.in.rs +++ b/src/model.in.rs @@ -1,7 +1,7 @@ // TODO: add `MathmMl` struct. /// `QueryResult` is the outer wrapper for all results from the query function. -#[derive(Clone, Debug, Deserialize, PartialEq)] +#[derive(Clone, Debug, PartialEq)] pub struct QueryResult { // Attributes pub success: bool, @@ -23,10 +23,7 @@ pub struct QueryResult { pub pod: Option>, pub assumptions: Option, pub sources: Option, - // TODO: find a way to parse errors. - // The naive method (uncommenting the following line) doesn't work as - // `QueryResult` also contains an `error` attribute. - //pub error: Option, + pub error: Option, pub tips: Option, pub didyoumeans: Option, pub languagemsg: Option, @@ -643,3 +640,1210 @@ impl Deserialize for States { deserializer.deserialize_struct("States", FIELDS, StatesVisitor) } } + +// This is a custom deserializer implementation, written for the purpose of +// being able to handle Wolfram|Alpha `QueryResult`s properly. This is necessary +// because Wolfram|Alpha returns an `error` attribute (always) and an `error` +// element (only when there's an error). +// +// This is nearly identical to the generated deserializer, except for in certain +// locations, where modifications have been indicated. +impl Deserialize for QueryResult { + fn deserialize<__D>(deserializer: &mut __D) -> Result + where __D: Deserializer, + { + #[allow(non_camel_case_types)] + enum __Field { + __field0, + __field1, + __field2, + __field3, + __field4, + __field5, + __field6, + __field7, + __field8, + __field9, + __field10, + __field11, + __field12, + __field13, + __field14, + __field15, + __field16, + __field17, + __field18, + __field19, + __field20, + __field21, + __field22, + __field23, + __field24, + __field25, + __ignore, + } + + impl Deserialize for __Field { + #[inline] + fn deserialize<__D>(deserializer: &mut __D) + -> Result<__Field, __D::Error> + where __D: Deserializer, + { + struct __FieldVisitor; + + impl Visitor for __FieldVisitor { + type Value = __Field; + + fn visit_usize<__E>(&mut self, + value: usize) + -> Result<__Field, __E> + where __E: SerdeError + { + match value { + 0usize => Ok(__Field::__field0), + 1usize => Ok(__Field::__field1), + 2usize => Ok(__Field::__field2), + 3usize => Ok(__Field::__field3), + 4usize => Ok(__Field::__field4), + 5usize => Ok(__Field::__field5), + 6usize => Ok(__Field::__field6), + 7usize => Ok(__Field::__field7), + 8usize => Ok(__Field::__field8), + 9usize => Ok(__Field::__field9), + 10usize => Ok(__Field::__field10), + 11usize => Ok(__Field::__field11), + 12usize => Ok(__Field::__field12), + 13usize => Ok(__Field::__field13), + 14usize => Ok(__Field::__field14), + 15usize => Ok(__Field::__field15), + 16usize => Ok(__Field::__field16), + 17usize => Ok(__Field::__field17), + 18usize => Ok(__Field::__field18), + 19usize => Ok(__Field::__field19), + 20usize => Ok(__Field::__field20), + 21usize => Ok(__Field::__field21), + 22usize => Ok(__Field::__field22), + 23usize => Ok(__Field::__field23), + 24usize => Ok(__Field::__field24), + 25usize => Ok(__Field::__field25), + _ => Ok(__Field::__ignore), + } + } + + fn visit_str<__E>(&mut self, value: &str) -> Result<__Field, __E> + where __E: SerdeError, + { + match value { + "success" => { Ok(__Field::__field0) } + // Renamed from `error_flag` to `error`. + "error" => { + Ok(__Field::__field1) + } + "numpods" => { Ok(__Field::__field2) } + "version" => { Ok(__Field::__field3) } + "datatypes" => { + Ok(__Field::__field4) + } + "timing" => { Ok(__Field::__field5) } + "timedout" => { + Ok(__Field::__field6) + } + "timedoutpods" => { + Ok(__Field::__field7) + } + "parsetiming" => { + Ok(__Field::__field8) + } + "parsetimedout" => { + Ok(__Field::__field9) + } + "recalculate" => { + Ok(__Field::__field10) + } + "id" => { Ok(__Field::__field11) } + "server" => { Ok(__Field::__field12) } + "related" => { + Ok(__Field::__field13) + } + "pod" => { Ok(__Field::__field14) } + "assumptions" => { + Ok(__Field::__field15) + } + "sources" => { + Ok(__Field::__field16) + } + // Commented out to avoid match arm conflicts.. + //"error" => { Ok(__Field::__field17) } + "tips" => { Ok(__Field::__field18) } + "didyoumeans" => { + Ok(__Field::__field19) + } + "languagemsg" => { + Ok(__Field::__field20) + } + "futuretopic" => { + Ok(__Field::__field21) + } + "relatedexamples" => { + Ok(__Field::__field22) + } + "examplepage" => { + Ok(__Field::__field23) + } + "generalization" => { + Ok(__Field::__field24) + } + "warnings" => { + Ok(__Field::__field25) + } + _ => Ok(__Field::__ignore), + } + } + + fn visit_bytes<__E>(&mut self, + value: &[u8]) + -> Result<__Field, __E> + where __E: SerdeError + { + match value { + b"success" => Ok(__Field::__field0), + // Renamed from `error_flag` to `error`. + b"error" => Ok(__Field::__field1), + b"numpods" => Ok(__Field::__field2), + b"version" => Ok(__Field::__field3), + b"datatypes" => Ok(__Field::__field4), + b"timing" => Ok(__Field::__field5), + b"timedout" => Ok(__Field::__field6), + b"timedoutpods" => Ok(__Field::__field7), + b"parsetiming" => Ok(__Field::__field8), + b"parsetimedout" => Ok(__Field::__field9), + b"recalculate" => Ok(__Field::__field10), + b"id" => Ok(__Field::__field11), + b"server" => Ok(__Field::__field12), + b"related" => Ok(__Field::__field13), + b"pod" => Ok(__Field::__field14), + b"assumptions" => Ok(__Field::__field15), + b"sources" => Ok(__Field::__field16), + // Commented out to avoid match arm conflicts.. + // b"error" => { Ok(__Field::__field17) } + b"tips" => Ok(__Field::__field18), + b"didyoumeans" => Ok(__Field::__field19), + b"languagemsg" => Ok(__Field::__field20), + b"futuretopic" => Ok(__Field::__field21), + b"relatedexamples" => Ok(__Field::__field22), + b"examplepage" => Ok(__Field::__field23), + b"generalization" => Ok(__Field::__field24), + b"warnings" => Ok(__Field::__field25), + _ => Ok(__Field::__ignore), + } + } + } + + deserializer.deserialize_struct_field(__FieldVisitor) + } + } + + struct __Visitor; + + impl Visitor for __Visitor { + type Value = QueryResult; + + #[inline] + fn visit_seq<__V>(&mut self, + mut visitor: __V) + -> Result + where __V: SeqVisitor + { + let __field0 = match match visitor.visit::() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } { + Some(value) => value, + None => { + match visitor.end() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }; + return Err(SerdeError::invalid_length(0usize)); + } + }; + let __field1 = match match visitor.visit::() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } { + Some(value) => value, + None => { + match visitor.end() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }; + return Err(SerdeError::invalid_length(1usize)); + } + }; + let __field2 = match match visitor.visit::() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } { + Some(value) => value, + None => { + match visitor.end() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }; + return Err(SerdeError::invalid_length(2usize)); + } + }; + let __field3 = match match visitor.visit::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } { + Some(value) => value, + None => { + match visitor.end() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }; + return Err(SerdeError::invalid_length(3usize)); + } + }; + let __field4 = match match visitor.visit::() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } { + Some(value) => value, + None => { + match visitor.end() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }; + return Err(SerdeError::invalid_length(4usize)); + } + }; + let __field5 = match match visitor.visit::() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } { + Some(value) => value, + None => { + match visitor.end() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }; + return Err(SerdeError::invalid_length(5usize)); + } + }; + let __field6 = match match visitor.visit::() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } { + Some(value) => value, + None => { + match visitor.end() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }; + return Err(SerdeError::invalid_length(6usize)); + } + }; + let __field7 = match match visitor.visit::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } { + Some(value) => value, + None => { + match visitor.end() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }; + return Err(SerdeError::invalid_length(7usize)); + } + }; + let __field8 = match match visitor.visit::() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } { + Some(value) => value, + None => { + match visitor.end() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }; + return Err(SerdeError::invalid_length(8usize)); + } + }; + let __field9 = match match visitor.visit::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } { + Some(value) => value, + None => { + match visitor.end() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }; + return Err(SerdeError::invalid_length(9usize)); + } + }; + let __field10 = match match visitor.visit::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } { + Some(value) => value, + None => { + match visitor.end() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }; + return Err(SerdeError::invalid_length(10usize)); + } + }; + let __field11 = match match visitor.visit::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } { + Some(value) => value, + None => { + match visitor.end() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }; + return Err(SerdeError::invalid_length(11usize)); + } + }; + let __field12 = match match visitor.visit::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } { + Some(value) => value, + None => { + match visitor.end() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }; + return Err(SerdeError::invalid_length(12usize)); + } + }; + let __field13 = match match visitor.visit::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } { + Some(value) => value, + None => { + match visitor.end() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }; + return Err(SerdeError::invalid_length(13usize)); + } + }; + let __field14 = match match visitor.visit::>>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } { + Some(value) => value, + None => { + match visitor.end() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }; + return Err(SerdeError::invalid_length(14usize)); + } + }; + let __field15 = match match visitor.visit::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } { + Some(value) => value, + None => { + match visitor.end() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }; + return Err(SerdeError::invalid_length(15usize)); + } + }; + let __field16 = match match visitor.visit::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } { + Some(value) => value, + None => { + match visitor.end() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }; + return Err(SerdeError::invalid_length(16usize)); + } + }; + let __field17 = match match visitor.visit::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } { + Some(value) => value, + None => { + match visitor.end() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }; + return Err(SerdeError::invalid_length(17usize)); + } + }; + let __field18 = match match visitor.visit::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } { + Some(value) => value, + None => { + match visitor.end() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }; + return Err(SerdeError::invalid_length(18usize)); + } + }; + let __field19 = match match visitor.visit::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } { + Some(value) => value, + None => { + match visitor.end() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }; + return Err(SerdeError::invalid_length(19usize)); + } + }; + let __field20 = match match visitor.visit::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } { + Some(value) => value, + None => { + match visitor.end() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }; + return Err(SerdeError::invalid_length(20usize)); + } + }; + let __field21 = match match visitor.visit::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } { + Some(value) => value, + None => { + match visitor.end() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }; + return Err(SerdeError::invalid_length(21usize)); + } + }; + let __field22 = match match visitor.visit::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } { + Some(value) => value, + None => { + match visitor.end() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }; + return Err(SerdeError::invalid_length(22usize)); + } + }; + let __field23 = match match visitor.visit::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } { + Some(value) => value, + None => { + match visitor.end() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }; + return Err(SerdeError::invalid_length(23usize)); + } + }; + let __field24 = match match visitor.visit::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } { + Some(value) => value, + None => { + match visitor.end() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }; + return Err(SerdeError::invalid_length(24usize)); + } + }; + let __field25 = match match visitor.visit::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } { + Some(value) => value, + None => { + match visitor.end() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }; + return Err(SerdeError::invalid_length(25usize)); + } + }; + match visitor.end() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }; + Ok(QueryResult { + success: __field0, + error_flag: __field1, + numpods: __field2, + version: __field3, + datatypes: __field4, + timing: __field5, + timedout: __field6, + timedoutpods: __field7, + parsetiming: __field8, + parsetimedout: __field9, + recalculate: __field10, + id: __field11, + server: __field12, + related: __field13, + pod: __field14, + assumptions: __field15, + sources: __field16, + error: __field17, + tips: __field18, + didyoumeans: __field19, + languagemsg: __field20, + futuretopic: __field21, + relatedexamples: __field22, + examplepage: __field23, + generalization: __field24, + warnings: __field25, + }) + } + + #[inline] + fn visit_map<__V>(&mut self, + mut visitor: __V) + -> Result + where __V: MapVisitor + { + let mut __field0: Option = None; + let mut __field1: Option = None; + let mut __field2: Option = None; + let mut __field3: Option> = None; + let mut __field4: Option = None; + let mut __field5: Option = None; + let mut __field6: Option = None; + let mut __field7: Option> = None; + let mut __field8: Option = None; + let mut __field9: Option> = None; + let mut __field10: Option> = None; + let mut __field11: Option> = None; + let mut __field12: Option> = None; + let mut __field13: Option> = None; + let mut __field14: Option>> = None; + let mut __field15: Option> = None; + let mut __field16: Option> = None; + let mut __field17: Option> = None; + let mut __field18: Option> = None; + let mut __field19: Option> = None; + let mut __field20: Option> = None; + let mut __field21: Option> = None; + let mut __field22: Option> = None; + let mut __field23: Option> = None; + let mut __field24: Option> = None; + let mut __field25: Option> = None; + while let Some(key) = match visitor.visit_key::<__Field>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } { + match key { + __Field::__field0 => { + if __field0.is_some() { + return Err(<__V::Error as + SerdeError>::duplicate_field("success")); + } + __field0 = Some(match visitor.visit_value::() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }); + } + // Modified to handle both the `error` attribute and + // element. If the attribute has already been + // deserialized, assume the next item is the `error` + // element. + __Field::__field1 => { + if __field1.is_some() { + if __field17.is_some() { + return Err(<__V::Error as + SerdeError>::duplicate_field("error")); + } + __field17 = Some(match visitor.visit_value::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }); + // return Err(<__V::Error as + // SerdeError>::duplicate_field("error_flag")); + } else { + __field1 = Some(match visitor.visit_value::() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }); + } + } + __Field::__field2 => { + if __field2.is_some() { + return Err(<__V::Error as + SerdeError>::duplicate_field("numpods")); + } + __field2 = Some(match visitor.visit_value::() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }); + } + __Field::__field3 => { + if __field3.is_some() { + return Err(<__V::Error as + SerdeError>::duplicate_field("version")); + } + __field3 = Some(match visitor.visit_value::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }); + } + __Field::__field4 => { + if __field4.is_some() { + return Err(<__V::Error as + SerdeError>::duplicate_field("datatypes")); + } + __field4 = Some(match visitor.visit_value::() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }); + } + __Field::__field5 => { + if __field5.is_some() { + return Err(<__V::Error as + SerdeError>::duplicate_field("timing")); + } + __field5 = Some(match visitor.visit_value::() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }); + } + __Field::__field6 => { + if __field6.is_some() { + return Err(<__V::Error as + SerdeError>::duplicate_field("timedout")); + } + __field6 = Some(match visitor.visit_value::() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }); + } + __Field::__field7 => { + if __field7.is_some() { + return Err(<__V::Error as + SerdeError>::duplicate_field("timedoutpods")); + } + __field7 = Some(match visitor.visit_value::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }); + } + __Field::__field8 => { + if __field8.is_some() { + return Err(<__V::Error as + SerdeError>::duplicate_field("parsetiming")); + } + __field8 = Some(match visitor.visit_value::() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }); + } + __Field::__field9 => { + if __field9.is_some() { + return Err(<__V::Error as + SerdeError>::duplicate_field("parsetimedout")); + } + __field9 = Some(match visitor.visit_value::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }); + } + __Field::__field10 => { + if __field10.is_some() { + return Err(<__V::Error as + SerdeError>::duplicate_field("recalculate")); + } + __field10 = Some(match visitor.visit_value::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }); + } + __Field::__field11 => { + if __field11.is_some() { + return Err(<__V::Error as + SerdeError>::duplicate_field("id")); + } + __field11 = Some(match visitor.visit_value::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }); + } + __Field::__field12 => { + if __field12.is_some() { + return Err(<__V::Error as + SerdeError>::duplicate_field("server")); + } + __field12 = Some(match visitor.visit_value::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }); + } + __Field::__field13 => { + if __field13.is_some() { + return Err(<__V::Error as + SerdeError>::duplicate_field("related")); + } + __field13 = Some(match visitor.visit_value::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }); + } + __Field::__field14 => { + if __field14.is_some() { + return Err(<__V::Error as + SerdeError>::duplicate_field("pod")); + } + __field14 = Some(match visitor.visit_value::>>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }); + } + __Field::__field15 => { + if __field15.is_some() { + return Err(<__V::Error as + SerdeError>::duplicate_field("assumptions")); + } + __field15 = Some(match visitor.visit_value::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }); + } + __Field::__field16 => { + if __field16.is_some() { + return Err(<__V::Error as + SerdeError>::duplicate_field("sources")); + } + __field16 = Some(match visitor.visit_value::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }); + } + __Field::__field17 => { + if __field17.is_some() { + return Err(<__V::Error as + SerdeError>::duplicate_field("error")); + } + __field17 = Some(match visitor.visit_value::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }); + } + __Field::__field18 => { + if __field18.is_some() { + return Err(<__V::Error as + SerdeError>::duplicate_field("tips")); + } + __field18 = Some(match visitor.visit_value::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }); + } + __Field::__field19 => { + if __field19.is_some() { + return Err(<__V::Error as + SerdeError>::duplicate_field("didyoumeans")); + } + __field19 = Some(match visitor.visit_value::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }); + } + __Field::__field20 => { + if __field20.is_some() { + return Err(<__V::Error as + SerdeError>::duplicate_field("languagemsg")); + } + __field20 = Some(match visitor.visit_value::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }); + } + __Field::__field21 => { + if __field21.is_some() { + return Err(<__V::Error as + SerdeError>::duplicate_field("futuretopic")); + } + __field21 = Some(match visitor.visit_value::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }); + } + __Field::__field22 => { + if __field22.is_some() { + return Err(<__V::Error as + SerdeError>::duplicate_field("relatedexamples")); + } + __field22 = + Some(match visitor.visit_value::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }); + } + __Field::__field23 => { + if __field23.is_some() { + return Err(<__V::Error as + SerdeError>::duplicate_field("examplepage")); + } + __field23 = Some(match visitor.visit_value::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }); + } + __Field::__field24 => { + if __field24.is_some() { + return Err(<__V::Error as + SerdeError>::duplicate_field("generalization")); + } + __field24 = + Some(match visitor.visit_value::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }); + } + __Field::__field25 => { + if __field25.is_some() { + return Err(<__V::Error as + SerdeError>::duplicate_field("warnings")); + } + __field25 = Some(match visitor.visit_value::>() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }); + } + _ => { + let _ = match visitor.visit_value::() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }; + } + } + } + match visitor.end() { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + }; + let __field0 = match __field0 { + Some(__field0) => __field0, + None => { + match visitor.missing_field("success") { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } + } + }; + let __field1 = match __field1 { + Some(__field1) => __field1, + // TODO: modified + None => { + match visitor.missing_field("error") { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } + } + }; + let __field2 = match __field2 { + Some(__field2) => __field2, + None => { + match visitor.missing_field("numpods") { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } + } + }; + let __field3 = match __field3 { + Some(__field3) => __field3, + None => { + match visitor.missing_field("version") { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } + } + }; + let __field4 = match __field4 { + Some(__field4) => __field4, + None => { + match visitor.missing_field("datatypes") { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } + } + }; + let __field5 = match __field5 { + Some(__field5) => __field5, + None => { + match visitor.missing_field("timing") { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } + } + }; + let __field6 = match __field6 { + Some(__field6) => __field6, + None => { + match visitor.missing_field("timedout") { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } + } + }; + let __field7 = match __field7 { + Some(__field7) => __field7, + None => { + match visitor.missing_field("timedoutpods") { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } + } + }; + let __field8 = match __field8 { + Some(__field8) => __field8, + None => { + match visitor.missing_field("parsetiming") { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } + } + }; + let __field9 = match __field9 { + Some(__field9) => __field9, + None => { + match visitor.missing_field("parsetimedout") { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } + } + }; + let __field10 = match __field10 { + Some(__field10) => __field10, + None => { + match visitor.missing_field("recalculate") { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } + } + }; + let __field11 = match __field11 { + Some(__field11) => __field11, + None => { + match visitor.missing_field("id") { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } + } + }; + let __field12 = match __field12 { + Some(__field12) => __field12, + None => { + match visitor.missing_field("server") { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } + } + }; + let __field13 = match __field13 { + Some(__field13) => __field13, + None => { + match visitor.missing_field("related") { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } + } + }; + let __field14 = match __field14 { + Some(__field14) => __field14, + None => { + match visitor.missing_field("pod") { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } + } + }; + let __field15 = match __field15 { + Some(__field15) => __field15, + None => { + match visitor.missing_field("assumptions") { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } + } + }; + let __field16 = match __field16 { + Some(__field16) => __field16, + None => { + match visitor.missing_field("sources") { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } + } + }; + let __field17 = match __field17 { + Some(__field17) => __field17, + None => { + match visitor.missing_field("error") { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } + } + }; + let __field18 = match __field18 { + Some(__field18) => __field18, + None => { + match visitor.missing_field("tips") { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } + } + }; + let __field19 = match __field19 { + Some(__field19) => __field19, + None => { + match visitor.missing_field("didyoumeans") { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } + } + }; + let __field20 = match __field20 { + Some(__field20) => __field20, + None => { + match visitor.missing_field("languagemsg") { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } + } + }; + let __field21 = match __field21 { + Some(__field21) => __field21, + None => { + match visitor.missing_field("futuretopic") { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } + } + }; + let __field22 = match __field22 { + Some(__field22) => __field22, + None => { + match visitor.missing_field("relatedexamples") { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } + } + }; + let __field23 = match __field23 { + Some(__field23) => __field23, + None => { + match visitor.missing_field("examplepage") { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } + } + }; + let __field24 = match __field24 { + Some(__field24) => __field24, + None => { + match visitor.missing_field("generalization") { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } + } + }; + let __field25 = match __field25 { + Some(__field25) => __field25, + None => { + match visitor.missing_field("warnings") { + Result::Ok(val) => val, + Result::Err(err) => return Result::Err(From::from(err)), + } + } + }; + Ok(QueryResult { + success: __field0, + error_flag: __field1, + numpods: __field2, + version: __field3, + datatypes: __field4, + timing: __field5, + timedout: __field6, + timedoutpods: __field7, + parsetiming: __field8, + parsetimedout: __field9, + recalculate: __field10, + id: __field11, + server: __field12, + related: __field13, + pod: __field14, + assumptions: __field15, + sources: __field16, + error: __field17, + tips: __field18, + didyoumeans: __field19, + languagemsg: __field20, + futuretopic: __field21, + relatedexamples: __field22, + examplepage: __field23, + generalization: __field24, + warnings: __field25, + }) + } + } + + const FIELDS: &'static [&'static str] = &[ + "success", + "error_flag", + "numpods", + "version", + "datatypes", + "timing", + "timedout", + "timedoutpods", + "parsetiming", + "parsetimedout", + "recalculate", + "id", + "server", + "related", + "pod", + "assumptions", + "sources", + "error", + "tips", + "didyoumeans", + "languagemsg", + "futuretopic", + "relatedexamples", + "examplepage", + "generalization", + "warnings", + ]; + deserializer.deserialize_struct("QueryResult", FIELDS, __Visitor) + } +} diff --git a/src/model.rs b/src/model.rs index 2822721..5d07416 100644 --- a/src/model.rs +++ b/src/model.rs @@ -17,6 +17,7 @@ use serde::{Deserialize, Deserializer, Error as SerdeError}; use serde::de::{MapVisitor, SeqVisitor, Visitor}; +use serde::de::impls::IgnoredAny; use url::Url; #[cfg(feature = "nightly")] From a3f03b7c236ae85cda6232e6a56d2a91b31055da Mon Sep 17 00:00:00 2001 From: Nikita Pekin Date: Sat, 17 Dec 2016 18:52:34 -0500 Subject: [PATCH 6/6] chore: replace `QueryResult` test 3 with 7 Remove `QueryResult` test 3 (it is a duplicate of `query_result_with_error`), and move test 7 into its place. --- src/model.rs | 3 +-- tests/sample-data/query_result_3.xml | 23 ++++++++++++++++------- tests/sample-data/query_result_7.xml | 17 ----------------- 3 files changed, 17 insertions(+), 26 deletions(-) delete mode 100644 tests/sample-data/query_result_7.xml diff --git a/src/model.rs b/src/model.rs index 5d07416..f5ec4dd 100644 --- a/src/model.rs +++ b/src/model.rs @@ -68,11 +68,10 @@ mod tests { fn test_query_result_deserializer() { from_str::(&read_sample_data_from_path("tests/sample-data/query_result_1.xml")).unwrap(); from_str::(&read_sample_data_from_path("tests/sample-data/query_result_2.xml")).unwrap(); - //from_str::(&read_sample_data_from_path("tests/sample-data/query_result_3.xml")).unwrap(); + from_str::(&read_sample_data_from_path("tests/sample-data/query_result_3.xml")).unwrap(); from_str::(&read_sample_data_from_path("tests/sample-data/query_result_4.xml")).unwrap(); from_str::(&read_sample_data_from_path("tests/sample-data/query_result_5.xml")).unwrap(); from_str::(&read_sample_data_from_path("tests/sample-data/query_result_6.xml")).unwrap(); - from_str::(&read_sample_data_from_path("tests/sample-data/query_result_7.xml")).unwrap(); } #[test] diff --git a/tests/sample-data/query_result_3.xml b/tests/sample-data/query_result_3.xml index 3b6834b..c7bd709 100644 --- a/tests/sample-data/query_result_3.xml +++ b/tests/sample-data/query_result_3.xml @@ -1,8 +1,17 @@ - - - - 2 - Appid missing - + + diff --git a/tests/sample-data/query_result_7.xml b/tests/sample-data/query_result_7.xml deleted file mode 100644 index c7bd709..0000000 --- a/tests/sample-data/query_result_7.xml +++ /dev/null @@ -1,17 +0,0 @@ - - -