pub enum Payload {
QualifyingResults(Vec<QualifyingResult>),
SprintResults(Vec<SprintResult>),
RaceResults(Vec<RaceResult>),
Laps(Vec<Lap>),
PitStops(Vec<PitStop>),
Schedule(Schedule),
}Expand description
Payload represents all the possible different data elements that be me returned as part of
a Race in a Response from the jolpica-f1 API.
For example, Payload::SprintResults corresponds to the "SprintResults" property key in the
JSON response, which is a list of SprintResult. One and only one of these payloads may be
returned in a given response, depending on the requested Resource, which is represented by
the different variants of this enum.
The variants and inner values may be matched and accessed via the usual pattern matching, or via
accessor functions provided by enum-as-inner.
§Examples:
let payload = Payload::Laps(vec![]);
let Payload::Laps(laps) = &payload else {
panic!("Expected Laps variant");
};
assert!(laps.is_empty());
assert!(payload.as_laps().unwrap().is_empty());Variants§
QualifyingResults(Vec<QualifyingResult>)
Contains a list of QualifyingResults, and corresponds to the "QualifyingResults"
property key in the JSON response from the jolpica-f1 API.
SprintResults(Vec<SprintResult>)
Contains a list of SprintResults, and corresponds to the "SprintResults" property key
in the JSON response from the jolpica-f1 API.
RaceResults(Vec<RaceResult>)
Contains a list of RaceResults, and corresponds to the "Results" property key in the
JSON response from the jolpica-f1 API.
Laps(Vec<Lap>)
Contains a list of Laps, and corresponds to the "Laps" property key in the JSON
response from the jolpica-f1 API.
PitStops(Vec<PitStop>)
Contains a list of PitStops, and corresponds to the "PitStops" property key in the
JSON response from the jolpica-f1 API.
Schedule(Schedule)
Contains a Schedule object, and corresponds to the absence of a tag property key in the
JSON response from the jolpica-f1 API. That is, all the elements of a schedule are flattened
directly into the Race object in JSON.
Note: Because of the untagged nature of this variant, and because all of the fields of
Schedule are optional, it no payload is returned this variant will be the one being set.
This is also a valid response from the jolpica-f1 API, e.g. for races prior to 2022, where
scheduling information was limited to the date/time of the Grand Prix (race), which is
already included in the Race object, as it does not depend on the Resource request.
Implementations§
Source§impl Payload
impl Payload
Sourcepub fn is_qualifying_results(&self) -> bool
pub fn is_qualifying_results(&self) -> bool
Returns true if this is a Payload::QualifyingResults, otherwise false
Sourcepub fn as_qualifying_results_mut(
&mut self,
) -> Option<&mut Vec<QualifyingResult>>
pub fn as_qualifying_results_mut( &mut self, ) -> Option<&mut Vec<QualifyingResult>>
Optionally returns mutable references to the inner fields if this is a Payload::QualifyingResults, otherwise None
Sourcepub fn as_qualifying_results(&self) -> Option<&Vec<QualifyingResult>>
pub fn as_qualifying_results(&self) -> Option<&Vec<QualifyingResult>>
Optionally returns references to the inner fields if this is a Payload::QualifyingResults, otherwise None
Sourcepub fn into_qualifying_results(self) -> Result<Vec<QualifyingResult>, Self>
pub fn into_qualifying_results(self) -> Result<Vec<QualifyingResult>, Self>
Returns the inner fields if this is a Payload::QualifyingResults, otherwise returns back the enum in the Err case of the result
Sourcepub fn is_sprint_results(&self) -> bool
pub fn is_sprint_results(&self) -> bool
Returns true if this is a Payload::SprintResults, otherwise false
Sourcepub fn as_sprint_results_mut(&mut self) -> Option<&mut Vec<SprintResult>>
pub fn as_sprint_results_mut(&mut self) -> Option<&mut Vec<SprintResult>>
Optionally returns mutable references to the inner fields if this is a Payload::SprintResults, otherwise None
Sourcepub fn as_sprint_results(&self) -> Option<&Vec<SprintResult>>
pub fn as_sprint_results(&self) -> Option<&Vec<SprintResult>>
Optionally returns references to the inner fields if this is a Payload::SprintResults, otherwise None
Sourcepub fn into_sprint_results(self) -> Result<Vec<SprintResult>, Self>
pub fn into_sprint_results(self) -> Result<Vec<SprintResult>, Self>
Returns the inner fields if this is a Payload::SprintResults, otherwise returns back the enum in the Err case of the result
Sourcepub fn is_race_results(&self) -> bool
pub fn is_race_results(&self) -> bool
Returns true if this is a Payload::RaceResults, otherwise false
Sourcepub fn as_race_results_mut(&mut self) -> Option<&mut Vec<RaceResult>>
pub fn as_race_results_mut(&mut self) -> Option<&mut Vec<RaceResult>>
Optionally returns mutable references to the inner fields if this is a Payload::RaceResults, otherwise None
Sourcepub fn as_race_results(&self) -> Option<&Vec<RaceResult>>
pub fn as_race_results(&self) -> Option<&Vec<RaceResult>>
Optionally returns references to the inner fields if this is a Payload::RaceResults, otherwise None
Sourcepub fn into_race_results(self) -> Result<Vec<RaceResult>, Self>
pub fn into_race_results(self) -> Result<Vec<RaceResult>, Self>
Returns the inner fields if this is a Payload::RaceResults, otherwise returns back the enum in the Err case of the result
Sourcepub fn as_laps_mut(&mut self) -> Option<&mut Vec<Lap>>
pub fn as_laps_mut(&mut self) -> Option<&mut Vec<Lap>>
Optionally returns mutable references to the inner fields if this is a Payload::Laps, otherwise None
Sourcepub fn as_laps(&self) -> Option<&Vec<Lap>>
pub fn as_laps(&self) -> Option<&Vec<Lap>>
Optionally returns references to the inner fields if this is a Payload::Laps, otherwise None
Sourcepub fn into_laps(self) -> Result<Vec<Lap>, Self>
pub fn into_laps(self) -> Result<Vec<Lap>, Self>
Returns the inner fields if this is a Payload::Laps, otherwise returns back the enum in the Err case of the result
Sourcepub fn is_pit_stops(&self) -> bool
pub fn is_pit_stops(&self) -> bool
Returns true if this is a Payload::PitStops, otherwise false
Sourcepub fn as_pit_stops_mut(&mut self) -> Option<&mut Vec<PitStop>>
pub fn as_pit_stops_mut(&mut self) -> Option<&mut Vec<PitStop>>
Optionally returns mutable references to the inner fields if this is a Payload::PitStops, otherwise None
Sourcepub fn as_pit_stops(&self) -> Option<&Vec<PitStop>>
pub fn as_pit_stops(&self) -> Option<&Vec<PitStop>>
Optionally returns references to the inner fields if this is a Payload::PitStops, otherwise None
Sourcepub fn into_pit_stops(self) -> Result<Vec<PitStop>, Self>
pub fn into_pit_stops(self) -> Result<Vec<PitStop>, Self>
Returns the inner fields if this is a Payload::PitStops, otherwise returns back the enum in the Err case of the result
Sourcepub fn is_schedule(&self) -> bool
pub fn is_schedule(&self) -> bool
Returns true if this is a Payload::Schedule, otherwise false
Sourcepub fn as_schedule_mut(&mut self) -> Option<&mut Schedule>
pub fn as_schedule_mut(&mut self) -> Option<&mut Schedule>
Optionally returns mutable references to the inner fields if this is a Payload::Schedule, otherwise None
Sourcepub fn as_schedule(&self) -> Option<&Schedule>
pub fn as_schedule(&self) -> Option<&Schedule>
Optionally returns references to the inner fields if this is a Payload::Schedule, otherwise None
Sourcepub fn into_schedule(self) -> Result<Schedule, Self>
pub fn into_schedule(self) -> Result<Schedule, Self>
Returns the inner fields if this is a Payload::Schedule, otherwise returns back the enum in the Err case of the result
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Payload
impl<'de> Deserialize<'de> for Payload
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Custom deserializer for Payload. It is functionally not very different from the one
provided by the Deserialize derive macro, except that, if there are any problems when
parsing one of the tagged variants - i.e. not Payload::Schedule - it will produce an
Err with a helpful message indicating what went wrong during parsing. The default
implementation would just result in Payload::Schedule with all fields set to None,
which usually later manifests as a cryptic and unhelpful Error::BadPayloadVariant.