pinboard_rs/api/query.rs
1// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
2// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
3// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
4// option. This file may not be copied, modified, or distributed
5// except according to those terms.
6
7use async_trait::async_trait;
8use http::Uri;
9use url::Url;
10
11use crate::api::{ApiError, AsyncClient, Client};
12
13pub fn url_to_http_uri(url: Url) -> Uri {
14 url.as_str()
15 .parse::<Uri>()
16 .expect("failed to parse a url::Url as an http::Uri")
17}
18
19/// A trait which represents a query for a Client
20pub trait Query<T, C>
21where
22 C: Client,
23{
24 /// Perform the query against the Client
25 fn query(&self, client: &C) -> Result<T, ApiError<C::Error>>;
26}
27
28/// A trait which represents a query for an AsyncClient
29#[async_trait]
30pub trait AsyncQuery<T, C>
31where
32 C: AsyncClient,
33{
34 /// Perform the query against the AsyncClient
35 async fn query_async(&self, client: &C) -> Result<T, ApiError<C::Error>>;
36}