freedom_api/extensions/
account.rs

1use std::future::Future;
2
3use crate::{api::Api, error::Error};
4use freedom_models::{account::Account, satellite::Satellite, user::User};
5
6pub trait AccountExt {
7    fn get_id(&self) -> Result<i32, Error>;
8
9    fn get_users<C>(
10        &self,
11        client: &C,
12    ) -> impl Future<Output = Result<Vec<User>, Error>> + Send + Sync
13    where
14        C: Api;
15
16    fn get_satellites<C>(
17        &self,
18        client: &C,
19    ) -> impl Future<Output = Result<Vec<Satellite>, Error>> + Send + Sync
20    where
21        C: Api;
22}
23
24impl AccountExt for Account {
25    fn get_id(&self) -> Result<i32, Error> {
26        super::get_id("self", &self.links)
27    }
28
29    async fn get_users<C>(&self, client: &C) -> Result<Vec<User>, Error>
30    where
31        C: Api,
32    {
33        super::get_item("users", &self.links, client).await
34    }
35
36    async fn get_satellites<C>(&self, client: &C) -> Result<Vec<Satellite>, Error>
37    where
38        C: Api,
39    {
40        super::get_embedded("satellites", &self.links, client).await
41    }
42}