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

This commit is contained in:
LordMZTE 2021-06-02 20:27:22 +02:00
parent df7d39971b
commit d7c0831c85
1 changed files with 7 additions and 3 deletions

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)?;