#[non_exhaustive]pub enum Answer {
Noul(NoulAnswer),
Choice(ChoiceAnswer),
Score(ScoreAnswer),
Unknown(Value),
}Expand description
The answer to one question. The type field mirrors the question’s type.
Parsing never fails on an answer this version of the crate does not understand. An unknown
type, or a known type whose body has changed shape, becomes Answer::Unknown holding the
raw JSON, so an upstream addition cannot take down the other answers in the response.
use jev_client::Answer;
let known: Answer = serde_json::from_str(r#"{"type":"noul","noul":0.92}"#).unwrap();
assert_eq!(known.as_noul().map(|answer| answer.noul), Some(0.92));
let newer: Answer = serde_json::from_str(r#"{"type":"rank","order":["b","a"]}"#).unwrap();
assert_eq!(newer.type_name(), Some("rank"));
assert!(matches!(newer, Answer::Unknown(_)));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Noul(NoulAnswer)
The probability that the answer to a yes/no question is yes.
Choice(ChoiceAnswer)
The chosen option and the probability of every option.
Score(ScoreAnswer)
The probability-weighted level and the probability of every level.
Unknown(Value)
An answer this version of the crate does not understand, kept as the raw JSON received.
Implementations§
Source§impl Answer
impl Answer
Sourcepub fn type_name(&self) -> Option<&str>
pub fn type_name(&self) -> Option<&str>
The wire name of the answer type, such as noul.
For Answer::Unknown this is whatever the server sent, or None when the answer had no
string type at all.
Sourcepub const fn as_noul(&self) -> Option<&NoulAnswer>
pub const fn as_noul(&self) -> Option<&NoulAnswer>
The answer as a NoulAnswer, when it is one.
Sourcepub const fn as_choice(&self) -> Option<&ChoiceAnswer>
pub const fn as_choice(&self) -> Option<&ChoiceAnswer>
The answer as a ChoiceAnswer, when it is one.
Sourcepub const fn as_score(&self) -> Option<&ScoreAnswer>
pub const fn as_score(&self) -> Option<&ScoreAnswer>
The answer as a ScoreAnswer, when it is one.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Answer
impl<'de> Deserialize<'de> for Answer
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>,
Source§impl From<ChoiceAnswer> for Answer
impl From<ChoiceAnswer> for Answer
Source§fn from(answer: ChoiceAnswer) -> Self
fn from(answer: ChoiceAnswer) -> Self
Source§impl From<NoulAnswer> for Answer
impl From<NoulAnswer> for Answer
Source§fn from(answer: NoulAnswer) -> Self
fn from(answer: NoulAnswer) -> Self
Source§impl From<ScoreAnswer> for Answer
impl From<ScoreAnswer> for Answer
Source§fn from(answer: ScoreAnswer) -> Self
fn from(answer: ScoreAnswer) -> Self
Source§impl JsonSchema for Answer
impl JsonSchema for Answer
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read more