speedrun_api/api/
query.rs

1use async_trait::async_trait;
2
3use super::{ApiError, AsyncClient, Client};
4
5pub(crate) fn url_to_http_uri(url: url::Url) -> http::Uri {
6    url.as_str()
7        .parse::<http::Uri>()
8        .expect("failed to parse url::Url as http::Uri")
9}
10
11/// Query made to a client.
12pub trait Query<T, C>
13where
14    C: Client,
15{
16    /// Perform a query against the client.
17    fn query(&self, client: &C) -> Result<T, ApiError<C::Error>>;
18}
19
20/// Asynchronous query made to a client.
21#[async_trait]
22pub trait AsyncQuery<T, C>
23where
24    C: AsyncClient,
25{
26    /// Perform an asynchronous query against the client.
27    async fn query_async(&self, client: &C) -> Result<T, ApiError<C::Error>>;
28}