freedom_api/extensions/
user.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use std::future::Future;

use crate::{api::Api, error::Error};
use freedom_models::{account::Account, user::User};

pub trait UserExt {
    fn get_id(&self) -> Result<i32, Error>;

    fn get_account<C>(&self, client: &C) -> impl Future<Output = Result<Account, Error>> + Send
    where
        C: Api + Send;
}

impl UserExt for User {
    fn get_id(&self) -> Result<i32, Error> {
        super::get_id("self", &self.links)
    }

    async fn get_account<C>(&self, client: &C) -> Result<Account, Error>
    where
        C: Api + Send,
    {
        super::get_content("account", &self.links, client).await
    }
}