41 lines
1,001 B
Rust
41 lines
1,001 B
Rust
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<String, Error> {
|
|
Ok(format!("user"))
|
|
}
|
|
}
|
|
|
|
impl RestPath<(Id, )> for User {
|
|
fn get_path(args: (Id, )) -> std::result::Result<String, Error> {
|
|
let (id, ) = args;
|
|
Ok(format!("user/{id}"))
|
|
}
|
|
}
|
|
|
|
pub async fn identity(client: &RestClient) -> Result<User, Error> {
|
|
Ok(client.get_with::<_, User>((), &[]).await?.into_inner())
|
|
}
|
|
|
|
pub async fn with_id(client: &RestClient, id: Id) -> Result<User, Error> {
|
|
Ok(client.get_with::<_, User>((id, ), &[]).await?.into_inner())
|
|
}
|