From 240882ffdfa422b700353d4a3da87560db1d9f2f Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Sun, 7 May 2023 12:39:04 +0200 Subject: [PATCH] Remove lifetime from Instance (see below) Originally, it was planned, that the Instance object would store Users. I have identified, that this was not needed, as it goes beyond the scope of a library; Users of this library are expected to keep track of users themselves. The removal of this user storage also prevented further overcomplications. --- src/api/auth/login.rs | 2 +- src/api/auth/register.rs | 2 +- src/api/policies/instance/instance.rs | 3 +-- src/api/types.rs | 6 +++--- src/api/users/users.rs | 10 +++++++++- src/instance.rs | 9 +++------ 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/api/auth/login.rs b/src/api/auth/login.rs index 23add11..f7c4fe6 100644 --- a/src/api/auth/login.rs +++ b/src/api/auth/login.rs @@ -8,7 +8,7 @@ pub mod login { use crate::errors::InstanceServerError; use crate::instance::Instance; - impl<'a> Instance<'a> { + impl Instance { pub async fn login_account( &mut self, login_schema: &LoginSchema, diff --git a/src/api/auth/register.rs b/src/api/auth/register.rs index b4d4fd1..b932b9f 100644 --- a/src/api/auth/register.rs +++ b/src/api/auth/register.rs @@ -8,7 +8,7 @@ pub mod register { instance::{Instance, Token}, }; - impl<'a> Instance<'a> { + impl Instance { /** Registers a new user on the Spacebar server. # Arguments diff --git a/src/api/policies/instance/instance.rs b/src/api/policies/instance/instance.rs index 19e841e..754d0b3 100644 --- a/src/api/policies/instance/instance.rs +++ b/src/api/policies/instance/instance.rs @@ -1,11 +1,10 @@ - use reqwest::Client; use serde_json::from_str; use crate::errors::InstanceServerError; use crate::{api::types::InstancePolicies, instance::Instance}; -impl<'a> Instance<'a> { +impl Instance { /** Gets the instance policies schema. # Errors diff --git a/src/api/types.rs b/src/api/types.rs index e218a83..20f3329 100644 --- a/src/api/types.rs +++ b/src/api/types.rs @@ -157,7 +157,7 @@ pub struct UserObject { #[derive(Debug)] pub struct User<'a> { pub logged_in: bool, - pub belongs_to: &'a mut Instance<'a>, + pub belongs_to: &'a mut Instance, token: String, pub limits: Limits, pub settings: UserSettings, @@ -169,7 +169,7 @@ impl<'a> User<'a> { self.logged_in } - pub fn belongs_to(&mut self) -> &mut Instance<'a> { + pub fn belongs_to(&mut self) -> &mut Instance { self.belongs_to } @@ -187,7 +187,7 @@ impl<'a> User<'a> { pub fn new( logged_in: bool, - belongs_to: &'a mut Instance<'a>, + belongs_to: &'a mut Instance, token: String, limits: Limits, settings: UserSettings, diff --git a/src/api/users/users.rs b/src/api/users/users.rs index e4d1678..77c38af 100644 --- a/src/api/users/users.rs +++ b/src/api/users/users.rs @@ -47,7 +47,7 @@ impl<'a> User<'a> { } } -impl<'a> Instance<'a> { +impl Instance { /** Get a user object by id, or get the current user. # Arguments @@ -72,3 +72,11 @@ impl<'a> Instance<'a> { .await } } + +#[cfg(test)] +mod test { + use super::*; + + #[tokio::test] + async fn get_user() {} +} diff --git a/src/instance.rs b/src/instance.rs index ad877f0..c20eaca 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -11,16 +11,15 @@ use std::fmt; /** The [`Instance`] what you will be using to perform all sorts of actions on the Spacebar server. */ -pub struct Instance<'a> { +pub struct Instance { pub urls: URLBundle, pub instance_info: InstancePolicies, pub requester: LimitedRequester, pub limits: Limits, //pub gateway: Gateway, - pub users: HashMap>, } -impl<'a> Instance<'a> { +impl Instance { /// Creates a new [`Instance`]. /// # Arguments /// * `urls` - The [`URLBundle`] that contains all the URLs that are needed to connect to the Spacebar server. @@ -30,8 +29,7 @@ impl<'a> Instance<'a> { pub async fn new( urls: URLBundle, requester: LimitedRequester, - ) -> Result, InstanceServerError> { - let users: HashMap = HashMap::new(); + ) -> Result { let mut instance = Instance { urls: urls.clone(), instance_info: InstancePolicies::new( @@ -47,7 +45,6 @@ impl<'a> Instance<'a> { ), limits: Limits::check_limits(urls.api).await, requester, - users, }; instance.instance_info = match instance.instance_policies_schema().await { Ok(schema) => schema,