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.
This commit is contained in:
bitfl0wer 2023-05-07 12:39:04 +02:00
parent 7904b3d9f8
commit 240882ffdf
6 changed files with 18 additions and 14 deletions

View File

@ -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,

View File

@ -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

View File

@ -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

View File

@ -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,

View File

@ -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() {}
}

View File

@ -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<Token, User<'a>>,
}
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<Instance<'a>, InstanceServerError> {
let users: HashMap<Token, User> = HashMap::new();
) -> Result<Instance, InstanceServerError> {
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,