diff options
author | Sam Tay <sam.chong.tay@gmail.com> | 2020-06-24 12:15:01 -0700 |
---|---|---|
committer | Sam Tay <sam.chong.tay@gmail.com> | 2020-06-24 12:15:01 -0700 |
commit | 59f6acca025f7a487ec5f6c32899226e0e5c9d5f (patch) | |
tree | db2bc39e9778306bb0080c941ab06469468e254e /src | |
parent | 32f25725e59741c2b8ef34821a4284083b522e3d (diff) |
Fix deserialization bug
Diffstat (limited to 'src')
-rw-r--r-- | src/stackexchange/api.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/stackexchange/api.rs b/src/stackexchange/api.rs index ff94de2..c9b69b4 100644 --- a/src/stackexchange/api.rs +++ b/src/stackexchange/api.rs @@ -41,6 +41,9 @@ pub struct Question<S> { #[serde(rename = "question_id")] pub id: u32, pub score: i32, + #[serde(default = "Vec::new")] + // N.B. empty vector default needed because questions endpoint cannot filter + // answers >= 1 pub answers: Vec<Answer<S>>, pub title: String, #[serde(rename = "body_markdown")] @@ -91,7 +94,10 @@ impl Api { .await? .json::<ResponseWrapper<Question<String>>>() .await? - .items; + .items + .into_iter() + .filter(|q| !q.answers.is_empty()) + .collect(); Ok(Self::preprocess(qs)) } |