2023-04-16 22:16:22 +02:00
|
|
|
use crate::api::schemas::schemas::InstancePoliciesSchema;
|
|
|
|
use crate::gateway::Gateway;
|
|
|
|
use crate::limit::LimitedRequester;
|
|
|
|
use crate::URLBundle;
|
|
|
|
|
|
|
|
use std::collections::HashMap;
|
2023-04-17 21:31:15 +02:00
|
|
|
use std::fmt;
|
2023-04-16 22:16:22 +02:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
2023-04-16 23:03:12 +02:00
|
|
|
/**
|
|
|
|
The [`Instance`] what you will be using to perform all sorts of actions on the Spacebar server.
|
|
|
|
*/
|
2023-04-16 22:16:22 +02:00
|
|
|
pub struct Instance {
|
|
|
|
urls: URLBundle,
|
|
|
|
instance_info: InstancePoliciesSchema,
|
|
|
|
requester: LimitedRequester,
|
2023-04-16 23:03:12 +02:00
|
|
|
gateway: Gateway,
|
2023-04-17 22:38:21 +02:00
|
|
|
users: HashMap<Token, Username>,
|
2023-04-16 23:03:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Instance {
|
|
|
|
pub fn new() {}
|
2023-04-16 22:16:22 +02:00
|
|
|
}
|
2023-04-17 21:31:15 +02:00
|
|
|
|
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
|
|
|
pub struct Token {
|
|
|
|
pub token: String,
|
|
|
|
}
|
|
|
|
|
2023-04-17 22:38:21 +02:00
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
|
|
|
pub struct Username {
|
|
|
|
pub username: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Username {
|
|
|
|
pub fn new(username: String) -> Result<Username, UsernameFormatError> {
|
|
|
|
if username.len() < 2 || username.len() > 32 {
|
|
|
|
return Err(UsernameFormatError::new(
|
|
|
|
"Username must be between 2 and 32 characters".to_string(),
|
|
|
|
));
|
2023-04-17 21:31:15 +02:00
|
|
|
}
|
2023-04-17 22:38:21 +02:00
|
|
|
return Ok(Username { username });
|
2023-04-17 21:31:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
2023-04-17 22:38:21 +02:00
|
|
|
pub struct UsernameFormatError {
|
2023-04-17 21:31:15 +02:00
|
|
|
pub message: String,
|
|
|
|
}
|
|
|
|
|
2023-04-17 22:38:21 +02:00
|
|
|
impl UsernameFormatError {
|
2023-04-17 21:31:15 +02:00
|
|
|
fn new(message: String) -> Self {
|
2023-04-17 22:38:21 +02:00
|
|
|
UsernameFormatError { message }
|
2023-04-17 21:31:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-17 22:38:21 +02:00
|
|
|
impl fmt::Display for UsernameFormatError {
|
2023-04-17 21:31:15 +02:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "{}", self.message)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-17 22:38:21 +02:00
|
|
|
impl std::error::Error for UsernameFormatError {}
|