Add lifetime to Instance
This commit is contained in:
parent
6858b1eb0d
commit
5edc92524c
|
@ -8,7 +8,7 @@ pub mod login {
|
||||||
use crate::errors::InstanceServerError;
|
use crate::errors::InstanceServerError;
|
||||||
use crate::instance::Instance;
|
use crate::instance::Instance;
|
||||||
|
|
||||||
impl Instance {
|
impl<'a> Instance<'a> {
|
||||||
pub async fn login_account(
|
pub async fn login_account(
|
||||||
&mut self,
|
&mut self,
|
||||||
login_schema: &LoginSchema,
|
login_schema: &LoginSchema,
|
||||||
|
|
|
@ -8,7 +8,7 @@ pub mod register {
|
||||||
instance::{Instance, Token},
|
instance::{Instance, Token},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl Instance {
|
impl<'a> Instance<'a> {
|
||||||
/**
|
/**
|
||||||
Registers a new user on the Spacebar server.
|
Registers a new user on the Spacebar server.
|
||||||
# Arguments
|
# 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::errors::InstanceServerError;
|
||||||
use crate::{api::types::InstancePolicies, instance::Instance};
|
use crate::{api::types::InstancePolicies, instance::Instance};
|
||||||
|
|
||||||
impl Instance {
|
impl<'a> Instance<'a> {
|
||||||
/**
|
/**
|
||||||
Gets the instance policies schema.
|
Gets the instance policies schema.
|
||||||
# Errors
|
# 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.
|
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 serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{api::limits::Limits, URLBundle};
|
use crate::{api::limits::Limits, instance::Instance};
|
||||||
|
|
||||||
pub trait WebSocketEvent {}
|
pub trait WebSocketEvent {}
|
||||||
|
|
||||||
|
@ -154,22 +152,22 @@ pub struct UserObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct User {
|
pub struct User<'a> {
|
||||||
logged_in: bool,
|
logged_in: bool,
|
||||||
belongs_to: URLBundle,
|
belongs_to: &'a Instance<'a>,
|
||||||
token: String,
|
token: String,
|
||||||
rate_limits: Limits,
|
rate_limits: Limits,
|
||||||
pub settings: UserSettings,
|
pub settings: UserSettings,
|
||||||
pub object: UserObject,
|
pub object: UserObject,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl User {
|
impl<'a> User<'a> {
|
||||||
pub fn is_logged_in(&self) -> bool {
|
pub fn is_logged_in(&self) -> bool {
|
||||||
self.logged_in
|
self.logged_in
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn belongs_to(&self) -> URLBundle {
|
pub fn belongs_to(&self) -> &Instance {
|
||||||
self.belongs_to.clone()
|
self.belongs_to
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn token(&self) -> String {
|
pub fn token(&self) -> String {
|
||||||
|
@ -186,12 +184,12 @@ impl User {
|
||||||
|
|
||||||
pub fn new(
|
pub fn new(
|
||||||
logged_in: bool,
|
logged_in: bool,
|
||||||
belongs_to: URLBundle,
|
belongs_to: &'a Instance<'a>,
|
||||||
token: String,
|
token: String,
|
||||||
rate_limits: Limits,
|
rate_limits: Limits,
|
||||||
settings: UserSettings,
|
settings: UserSettings,
|
||||||
object: UserObject,
|
object: UserObject,
|
||||||
) -> User {
|
) -> User<'a> {
|
||||||
User {
|
User {
|
||||||
logged_in,
|
logged_in,
|
||||||
belongs_to,
|
belongs_to,
|
||||||
|
@ -206,7 +204,7 @@ impl User {
|
||||||
#[derive(Debug, Serialize, Deserialize, Default)]
|
#[derive(Debug, Serialize, Deserialize, Default)]
|
||||||
pub struct Message {
|
pub struct Message {
|
||||||
id: String,
|
id: String,
|
||||||
channel_id: String,
|
pub channel_id: String,
|
||||||
author: UserObject,
|
author: UserObject,
|
||||||
content: String,
|
content: String,
|
||||||
timestamp: 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.
|
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 urls: URLBundle,
|
||||||
pub instance_info: InstancePolicies,
|
pub instance_info: InstancePolicies,
|
||||||
pub requester: LimitedRequester,
|
pub requester: LimitedRequester,
|
||||||
pub limits: Limits,
|
pub limits: Limits,
|
||||||
//pub gateway: Gateway,
|
//pub gateway: Gateway,
|
||||||
pub users: HashMap<Token, User>,
|
pub users: HashMap<Token, User<'a>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Instance {
|
impl<'a> Instance<'a> {
|
||||||
/// Creates a new [`Instance`].
|
/// Creates a new [`Instance`].
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
/// * `urls` - The [`URLBundle`] that contains all the URLs that are needed to connect to the Spacebar server.
|
/// * `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(
|
pub async fn new(
|
||||||
urls: URLBundle,
|
urls: URLBundle,
|
||||||
requester: LimitedRequester,
|
requester: LimitedRequester,
|
||||||
) -> Result<Instance, InstanceServerError> {
|
) -> Result<Instance<'a>, InstanceServerError> {
|
||||||
let users: HashMap<Token, User> = HashMap::new();
|
let users: HashMap<Token, User> = HashMap::new();
|
||||||
let mut instance = Instance {
|
let mut instance = Instance {
|
||||||
urls: urls.clone(),
|
urls: urls.clone(),
|
||||||
|
|
Loading…
Reference in New Issue