Payload

Enum Payload 

Source
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

Source

pub fn is_qualifying_results(&self) -> bool

Returns true if this is a Payload::QualifyingResults, otherwise false

Source

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

Source

pub fn as_qualifying_results(&self) -> Option<&Vec<QualifyingResult>>

Optionally returns references to the inner fields if this is a Payload::QualifyingResults, otherwise None

Source

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

Source

pub fn is_sprint_results(&self) -> bool

Returns true if this is a Payload::SprintResults, otherwise false

Source

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

Source

pub fn as_sprint_results(&self) -> Option<&Vec<SprintResult>>

Optionally returns references to the inner fields if this is a Payload::SprintResults, otherwise None

Source

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

Source

pub fn is_race_results(&self) -> bool

Returns true if this is a Payload::RaceResults, otherwise false

Source

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

Source

pub fn as_race_results(&self) -> Option<&Vec<RaceResult>>

Optionally returns references to the inner fields if this is a Payload::RaceResults, otherwise None

Source

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

Source

pub fn is_laps(&self) -> bool

Returns true if this is a Payload::Laps, otherwise false

Source

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

Source

pub fn as_laps(&self) -> Option<&Vec<Lap>>

Optionally returns references to the inner fields if this is a Payload::Laps, otherwise None

Source

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

Source

pub fn is_pit_stops(&self) -> bool

Returns true if this is a Payload::PitStops, otherwise false

Source

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

Source

pub fn as_pit_stops(&self) -> Option<&Vec<PitStop>>

Optionally returns references to the inner fields if this is a Payload::PitStops, otherwise None

Source

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

Source

pub fn is_schedule(&self) -> bool

Returns true if this is a Payload::Schedule, otherwise false

Source

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

Source

pub fn as_schedule(&self) -> Option<&Schedule>

Optionally returns references to the inner fields if this is a Payload::Schedule, otherwise None

Source

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 Clone for Payload

Source§

fn clone(&self) -> Payload

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Payload

Source§

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

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

impl<'de> Deserialize<'de> for Payload

Source§

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.

Source§

impl From<Payload> for Error

Source§

fn from(_: Payload) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Payload

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Payload

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<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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

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