You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yuurei/src/state/mod.rs

61 lines
1.1 KiB

use super::*;
use std::collections::{HashMap, HashSet};
use std::sync::Arc;
use tokio::sync::RwLock;
use generational_arena::{
Arena,Index,
4 years ago
};
use user::{User, UserID};
use post::{Post, PostID};
mod freeze;
pub use freeze::*;
#[derive(Debug)]
struct Oneesan
{
users: Arena<Arc<RwLock<User>>>,
posts: Arena<Arc<RwLock<Post>>>,
/// Maps `UserID`s to indexes in the `users` arena.
users_map: HashMap<UserID, Index>,
/// Maps `PostID`s to indexies in the `posts` arena.
posts_map: HashMap<PostID, Index>,
/// Maps `UserID`s to the user's owned posts in the `posts` arena.
posts_user_map: HashMap<UserID, MaybeVec<Index>>,
}
4 years ago
#[derive(Debug)]
struct Inner
{
/// The posts and user state.
oneesan: RwLock<Oneesan>,
}
/// Contains all posts and users
#[derive(Debug, Clone)]
pub struct State(Arc<Inner>);
4 years ago
impl State
{
/// Create a new empty state
pub fn new() -> Self
{
Self(Arc::new(
Inner {
oneesan: RwLock::new(Oneesan {
users: Arena::new(),
posts: Arena::new(),
users_map: HashMap::new(),
posts_map: HashMap::new(),
posts_user_map: HashMap::new(),
4 years ago
})
}
))
}
}