naia_server/
user_scope.rs1use std::hash::Hash;
2
3use super::{server::Server, user::UserKey};
4
5pub struct UserScopeRef<'s, E: Copy + Eq + Hash + Send + Sync> {
6 server: &'s Server<E>,
7 key: UserKey,
8}
9
10impl<'s, E: Copy + Eq + Hash + Send + Sync> UserScopeRef<'s, E> {
11 pub fn new(server: &'s Server<E>, key: &UserKey) -> Self {
12 Self { server, key: *key }
13 }
14
15 pub fn has(&self, entity: &E) -> bool {
17 self.server.user_scope_has_entity(&self.key, entity)
18 }
19}
20
21pub struct UserScopeMut<'s, E: Copy + Eq + Hash + Send + Sync> {
22 server: &'s mut Server<E>,
23 key: UserKey,
24}
25
26impl<'s, E: Copy + Eq + Hash + Send + Sync> UserScopeMut<'s, E> {
27 pub fn new(server: &'s mut Server<E>, key: &UserKey) -> Self {
28 Self { server, key: *key }
29 }
30
31 pub fn has(&self, entity: &E) -> bool {
33 self.server.user_scope_has_entity(&self.key, entity)
34 }
35
36 pub fn include(&mut self, entity: &E) -> &mut Self {
38 self.server.user_scope_set_entity(&self.key, entity, true);
39
40 self
41 }
42
43 pub fn exclude(&mut self, entity: &E) -> &mut Self {
45 self.server.user_scope_set_entity(&self.key, entity, false);
46
47 self
48 }
49
50 pub fn clear(&mut self) -> &mut Self {
52 self.server.user_scope_remove_user(&self.key);
53
54 self
55 }
56}