Skip to main content

Answers

Struct Answers 

Source
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

Source

pub fn len(&self) -> usize

How many answers there are.

Source

pub fn is_empty(&self) -> bool

Whether there are none.

Source

pub fn get(&self, name: &str) -> Option<&Answer>

The answer to the question called name.

Source

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.

Source

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.

Source

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.

Source

pub fn iter( &self, ) -> impl ExactSizeIterator<Item = (&str, &Answer)> + DoubleEndedIterator

Every answer with its question name, in the order received.

Source

pub fn names(&self) -> impl ExactSizeIterator<Item = &str> + DoubleEndedIterator

The question names, in the order received.

Source

pub fn nouls(&self) -> impl DoubleEndedIterator<Item = (&str, &NoulAnswer)>

The yes/no answers, in the order received.

Source

pub fn choices(&self) -> impl DoubleEndedIterator<Item = (&str, &ChoiceAnswer)>

The choice answers, in the order received.

Source

pub fn scores(&self) -> impl DoubleEndedIterator<Item = (&str, &ScoreAnswer)>

The score answers, in the order received.

Trait Implementations§

Source§

impl AnswerSet for Answers

Source§

fn deserialize_answers<'de, D>( deserializer: D, context: AnswerContext, ) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Reads the answers object of a response. Read more
Source§

impl Clone for Answers

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Answers

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Answers

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Answers

Source§

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.

Source§

impl<S> FromIterator<(S, Answer)> for Answers
where S: Into<String>,

Source§

fn from_iter<I>(iter: I) -> Self
where I: IntoIterator<Item = (S, Answer)>,

Creates a value from an iterator. Read more
Source§

impl PartialEq for Answers

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Answers

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Answers

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more