use serde::Deserialize; use restson::{RestClient, RestPath, Error}; use super::{ UserId as Id, }; #[derive(Debug, Deserialize)] pub struct User { pub id: Id, #[serde(flatten)] unknown: serde_json::Value, } impl std::fmt::Display for User { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", serde_json::to_string_pretty(&self.unknown).unwrap()) } } impl RestPath<()> for User { fn get_path(_: ()) -> std::result::Result { Ok(format!("user")) } } impl RestPath<(Id, )> for User { fn get_path(args: (Id, )) -> std::result::Result { let (id, ) = args; Ok(format!("user/{id}")) } } pub async fn identity(client: &RestClient) -> Result { Ok(client.get_with::<_, User>((), &[]).await?.into_inner()) } pub async fn with_id(client: &RestClient, id: Id) -> Result { Ok(client.get_with::<_, User>((id, ), &[]).await?.into_inner()) }