pub struct Answers { /* private fields */ }Expand description
The answers of a response, looked up by question name.
The answers are kept in the order the server sent them, which is the order the questions were asked in. A lookup scans them, which for the handful of questions a call carries is faster than hashing the name. Should a document name one question twice - JSON allows it, the API does not do it - both answers are kept and a lookup finds the first.
The typed accessors (nouls and friends) filter as they
iterate; nothing is copied or cached.
Implementations§
Source§impl Answers
impl Answers
Sourcepub fn noul(&self, name: &str) -> Option<&NoulAnswer>
pub fn noul(&self, name: &str) -> Option<&NoulAnswer>
The answer to the yes/no question called name, if there is one and it
is a yes/no answer.
Sourcepub fn choice(&self, name: &str) -> Option<&ChoiceAnswer>
pub fn choice(&self, name: &str) -> Option<&ChoiceAnswer>
The answer to the choice question called name, if there is one and it
is a choice answer.
Sourcepub fn score(&self, name: &str) -> Option<&ScoreAnswer>
pub fn score(&self, name: &str) -> Option<&ScoreAnswer>
The answer to the score question called name, if there is one and it
is a score answer.
Sourcepub fn iter(
&self,
) -> impl ExactSizeIterator<Item = (&str, &Answer)> + DoubleEndedIterator
pub fn iter( &self, ) -> impl ExactSizeIterator<Item = (&str, &Answer)> + DoubleEndedIterator
Every answer with its question name, in the order received.
Sourcepub fn names(&self) -> impl ExactSizeIterator<Item = &str> + DoubleEndedIterator
pub fn names(&self) -> impl ExactSizeIterator<Item = &str> + DoubleEndedIterator
The question names, in the order received.
Sourcepub fn nouls(&self) -> impl DoubleEndedIterator<Item = (&str, &NoulAnswer)>
pub fn nouls(&self) -> impl DoubleEndedIterator<Item = (&str, &NoulAnswer)>
The yes/no answers, in the order received.
Sourcepub fn choices(&self) -> impl DoubleEndedIterator<Item = (&str, &ChoiceAnswer)>
pub fn choices(&self) -> impl DoubleEndedIterator<Item = (&str, &ChoiceAnswer)>
The choice answers, in the order received.
Sourcepub fn scores(&self) -> impl DoubleEndedIterator<Item = (&str, &ScoreAnswer)>
pub fn scores(&self) -> impl DoubleEndedIterator<Item = (&str, &ScoreAnswer)>
The score answers, in the order received.
Trait Implementations§
Source§impl AnswerSet for Answers
impl AnswerSet for Answers
Source§fn deserialize_answers<'de, D>(
deserializer: D,
context: AnswerContext,
) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize_answers<'de, D>(
deserializer: D,
context: AnswerContext,
) -> Result<Self, D::Error>where
D: Deserializer<'de>,
answers object of a response. Read moreSource§impl<'de> Deserialize<'de> for Answers
impl<'de> Deserialize<'de> for Answers
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Reads answers with no expectation about their number. Answers of a type this version does not model are skipped, as they are in a response.
Reloading is supported through a JSON codec (sonic-rs, serde_json);
see ScoreAnswer for what a non-JSON serde format cannot read back.