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