1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use std::hash::Hash;

use super::{server::Server, user::UserKey};

pub struct UserScopeRef<'s, E: Copy + Eq + Hash + Send + Sync> {
    server: &'s Server<E>,
    key: UserKey,
}

impl<'s, E: Copy + Eq + Hash + Send + Sync> UserScopeRef<'s, E> {
    pub fn new(server: &'s Server<E>, key: &UserKey) -> Self {
        Self { server, key: *key }
    }

    /// Returns true if the User's scope contains the Entity
    pub fn has(&self, entity: &E) -> bool {
        self.server.user_scope_has_entity(&self.key, entity)
    }
}

pub struct UserScopeMut<'s, E: Copy + Eq + Hash + Send + Sync> {
    server: &'s mut Server<E>,
    key: UserKey,
}

impl<'s, E: Copy + Eq + Hash + Send + Sync> UserScopeMut<'s, E> {
    pub fn new(server: &'s mut Server<E>, key: &UserKey) -> Self {
        Self { server, key: *key }
    }

    /// Returns true if the User's scope contains the Entity
    pub fn has(&self, entity: &E) -> bool {
        self.server.user_scope_has_entity(&self.key, entity)
    }

    /// Adds an Entity to the User's scope
    pub fn include(&mut self, entity: &E) -> &mut Self {
        self.server.user_scope_set_entity(&self.key, entity, true);

        self
    }

    /// Removes an Entity from the User's scope
    pub fn exclude(&mut self, entity: &E) -> &mut Self {
        self.server.user_scope_set_entity(&self.key, entity, false);

        self
    }

    /// Removes all Entities from the User's scope
    pub fn clear(&mut self) -> &mut Self {
        self.server.user_scope_remove_user(&self.key);

        self
    }
}