openf1 0.1.0

Unofficial Rust client for the OpenF1 API
Documentation
use std::marker::PhantomData;

use serde::de::DeserializeOwned;

use crate::query::QueryParams;
use crate::OpenF1Client;
use crate::OpenF1Error;

pub struct ResourceClient<'a, T> {
    client: &'a OpenF1Client,
    resource: &'static str,
    _marker: PhantomData<T>,
}

impl<'a, T> ResourceClient<'a, T> {
    pub(crate) fn new(client: &'a OpenF1Client, resource: &'static str) -> Self {
        Self {
            client,
            resource,
            _marker: PhantomData,
        }
    }

    pub async fn list(&self, params: impl Into<QueryParams>) -> Result<Vec<T>, OpenF1Error>
    where
        T: DeserializeOwned,
    {
        self.client.list_typed(self.resource, params.into()).await
    }

    pub async fn list_csv(&self, params: impl Into<QueryParams>) -> Result<String, OpenF1Error> {
        self.client.list_csv(self.resource, params.into()).await
    }
}