use HRTB to get rid of DeserializeOwned trait bound in get_api_json
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
LordMZTE 2021-06-02 20:27:22 +02:00
parent df7d39971b
commit d7c0831c85

View file

@ -2,7 +2,7 @@ use crate::api::{Category, CatsResp, Meme, MemesResp, User, UsersResp};
use log::info;
use once_cell::sync::OnceCell;
use reqwest::Url;
use serde::de::DeserializeOwned;
use serde::Deserialize;
use std::sync::Arc;
use thiserror::Error;
use tokio::sync::Mutex;
@ -36,12 +36,16 @@ impl JMClient {
JMClientBuilder::default()
}
async fn get_api_json<R: DeserializeOwned, T, F: FnOnce(R) -> T>(
async fn get_api_json<R, T, F>(
&self,
cache: &OnceCell<Arc<T>>,
endpoint: &str,
res_to_data: F,
) -> Result<Arc<T>, JMClientError> {
) -> Result<Arc<T>, JMClientError>
where
for<'de> R: Deserialize<'de>,
F: FnOnce(R) -> T,
{
Ok(init_cache!(cache, {
info!("Requesting {} from server", endpoint);
let url = self.endpoint.join(endpoint)?;