use derive_more::Deref; use serde::Deserialize; use tracing::instrument; use crate::{Client, Error}; #[derive(Debug, Deserialize)] pub(crate) struct AlcoholicDto { #[serde(rename = "strAlcoholic")] alcoholic: String, } #[derive(Debug, Deserialize)] pub(crate) struct AlcoholicsDto { drinks: Vec, } #[derive(Debug, Deref)] pub struct Alcoholic(String); impl From for Alcoholic { fn from(value: AlcoholicDto) -> Self { Self(value.alcoholic) } } #[derive(Debug, Deref)] pub struct Alcoholics(Vec); impl Alcoholics { /// List the alcoholics #[instrument] pub async fn list(client: &Client) -> Result { Ok(reqwest::get(client.base_url.join("list.php?a=list")?.to_string()) .await? .json::() .await? .into()) } } impl From for Alcoholics { fn from(value: AlcoholicsDto) -> Self { Self(value.drinks.into_iter().map(Into::into).collect()) } }