Add lifetime to Instance
This commit is contained in:
parent
13815e73a1
commit
7445f1efc7
|
@ -8,7 +8,7 @@ pub mod login {
|
|||
use crate::errors::InstanceServerError;
|
||||
use crate::instance::Instance;
|
||||
|
||||
impl Instance {
|
||||
impl<'a> Instance<'a> {
|
||||
pub async fn login_account(
|
||||
&mut self,
|
||||
login_schema: &LoginSchema,
|
||||
|
|
|
@ -8,7 +8,7 @@ pub mod register {
|
|||
instance::{Instance, Token},
|
||||
};
|
||||
|
||||
impl Instance {
|
||||
impl<'a> Instance<'a> {
|
||||
/**
|
||||
Registers a new user on the Spacebar server.
|
||||
# Arguments
|
||||
|
|
|
@ -49,5 +49,5 @@ pub mod messages {
|
|||
}
|
||||
}
|
||||
|
||||
impl User {}
|
||||
impl<'a> User<'a> {}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ pub mod instance {
|
|||
use crate::errors::InstanceServerError;
|
||||
use crate::{api::types::InstancePolicies, instance::Instance};
|
||||
|
||||
impl Instance {
|
||||
impl<'a> Instance<'a> {
|
||||
/**
|
||||
Gets the instance policies schema.
|
||||
# Errors
|
||||
|
|
|
@ -4,11 +4,9 @@ https://discord.com/developers/docs .
|
|||
I do not feel like re-documenting all of this, as everything is already perfectly explained there.
|
||||
*/
|
||||
|
||||
use std::fmt;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{api::limits::Limits, URLBundle};
|
||||
use crate::{api::limits::Limits, instance::Instance};
|
||||
|
||||
pub trait WebSocketEvent {}
|
||||
|
||||
|
@ -154,22 +152,22 @@ pub struct UserObject {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct User {
|
||||
pub struct User<'a> {
|
||||
logged_in: bool,
|
||||
belongs_to: URLBundle,
|
||||
belongs_to: &'a Instance<'a>,
|
||||
token: String,
|
||||
rate_limits: Limits,
|
||||
pub settings: UserSettings,
|
||||
pub object: UserObject,
|
||||
}
|
||||
|
||||
impl User {
|
||||
impl<'a> User<'a> {
|
||||
pub fn is_logged_in(&self) -> bool {
|
||||
self.logged_in
|
||||
}
|
||||
|
||||
pub fn belongs_to(&self) -> URLBundle {
|
||||
self.belongs_to.clone()
|
||||
pub fn belongs_to(&self) -> &Instance {
|
||||
self.belongs_to
|
||||
}
|
||||
|
||||
pub fn token(&self) -> String {
|
||||
|
@ -186,12 +184,12 @@ impl User {
|
|||
|
||||
pub fn new(
|
||||
logged_in: bool,
|
||||
belongs_to: URLBundle,
|
||||
belongs_to: &'a Instance<'a>,
|
||||
token: String,
|
||||
rate_limits: Limits,
|
||||
settings: UserSettings,
|
||||
object: UserObject,
|
||||
) -> User {
|
||||
) -> User<'a> {
|
||||
User {
|
||||
logged_in,
|
||||
belongs_to,
|
||||
|
@ -206,7 +204,7 @@ impl User {
|
|||
#[derive(Debug, Serialize, Deserialize, Default)]
|
||||
pub struct Message {
|
||||
id: String,
|
||||
channel_id: String,
|
||||
pub channel_id: String,
|
||||
author: UserObject,
|
||||
content: String,
|
||||
timestamp: String,
|
||||
|
|
|
@ -11,16 +11,16 @@ use std::fmt;
|
|||
/**
|
||||
The [`Instance`] what you will be using to perform all sorts of actions on the Spacebar server.
|
||||
*/
|
||||
pub struct Instance {
|
||||
pub struct Instance<'a> {
|
||||
pub urls: URLBundle,
|
||||
pub instance_info: InstancePolicies,
|
||||
pub requester: LimitedRequester,
|
||||
pub limits: Limits,
|
||||
//pub gateway: Gateway,
|
||||
pub users: HashMap<Token, User>,
|
||||
pub users: HashMap<Token, User<'a>>,
|
||||
}
|
||||
|
||||
impl Instance {
|
||||
impl<'a> Instance<'a> {
|
||||
/// Creates a new [`Instance`].
|
||||
/// # Arguments
|
||||
/// * `urls` - The [`URLBundle`] that contains all the URLs that are needed to connect to the Spacebar server.
|
||||
|
@ -30,7 +30,7 @@ impl Instance {
|
|||
pub async fn new(
|
||||
urls: URLBundle,
|
||||
requester: LimitedRequester,
|
||||
) -> Result<Instance, InstanceServerError> {
|
||||
) -> Result<Instance<'a>, InstanceServerError> {
|
||||
let users: HashMap<Token, User> = HashMap::new();
|
||||
let mut instance = Instance {
|
||||
urls: urls.clone(),
|
||||
|
|
Loading…
Reference in New Issue