twilight_cache_any_backend/model/
role.rs

1use twilight_model::{
2    guild::{Permissions, Role, RoleTags},
3    id::{
4        marker::{GuildMarker, RoleMarker, UserMarker},
5        Id,
6    },
7    util::ImageHash,
8};
9
10/// A cached emoji
11///
12/// It's the same as [`twilight_model::guild::Role`] except:
13///
14/// - `guild_id` field is added, making it possible to return a guild's roles
15///
16/// - `user_id` field is added, making it possible to return a member's roles
17#[derive(Clone, Debug)]
18pub struct CachedRole {
19    pub guild_id: Id<GuildMarker>,
20    pub user_id: Option<Id<UserMarker>>,
21    pub color: u32,
22    pub hoist: bool,
23    pub icon: Option<ImageHash>,
24    pub id: Id<RoleMarker>,
25    pub managed: bool,
26    pub mentionable: bool,
27    pub name: String,
28    pub permissions: Permissions,
29    pub position: i64,
30    pub tags: Option<RoleTags>,
31    pub unicode_emoji: Option<String>,
32}
33
34impl CachedRole {
35    /// Create a cached role from a given role and guild ID
36    #[allow(clippy::missing_const_for_fn)]
37    #[must_use]
38    pub fn from_role(role: Role, guild_id: Id<GuildMarker>) -> Self {
39        Self {
40            guild_id,
41            user_id: None,
42            color: role.color,
43            hoist: role.hoist,
44            icon: role.icon,
45            id: role.id,
46            managed: role.managed,
47            mentionable: role.mentionable,
48            name: role.name,
49            permissions: role.permissions,
50            position: role.position,
51            tags: role.tags,
52            unicode_emoji: role.unicode_emoji,
53        }
54    }
55}