essence 0.7.0

Essential models and database logic for the Adapt chat platform.
Documentation
use crate::models::{ExtendedColor, PermissionPair};
use crate::serde_for_bitflags;
#[cfg(feature = "client")]
use serde::Deserialize;
use serde::Serialize;
#[cfg(feature = "utoipa")]
use utoipa::ToSchema;

/// A role in a guild.
#[derive(Clone, Debug, Default, Serialize)]
#[cfg_attr(feature = "client", derive(Deserialize))]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
#[cfg_attr(feature = "bincode", derive(bincode::Encode, bincode::Decode))]
pub struct Role {
    /// The snowflake ID of the role.
    pub id: u64,
    /// The ID of the guild this role belongs to.
    pub guild_id: u64,
    /// The name of the role.
    pub name: String,
    /// The color of the role, or ``None`` if the role has no color (in which case it inherits the
    /// color).
    pub color: Option<ExtendedColor>,
    /// The URL of the role's icon, if any, displayed alongside member names in chat.
    pub icon: Option<String>,
    /// The permissions users with this role have.
    #[cfg_attr(feature = "bincode", bincode(with_serde))]
    pub permissions: PermissionPair,
    /// The position of this role in the role hierarchy. The lower the number, the lower the role.
    /// The default role always has a position of 0.
    ///
    /// The backend will try its best to keep all role positions unique, but on the event two
    /// collide due to something such as a data race, then the true position of these roles will
    /// not be predictable, and will likely be in the order of model creation.
    pub position: u16,
    /// A bitmask of flags representing extra metadata about the role.
    #[cfg_attr(feature = "bincode", bincode(with_serde))]
    pub flags: RoleFlags,
}

bitflags::bitflags! {
    #[derive(Default)]
    pub struct RoleFlags: u32 {
        /// Whether the role is hoisted, or shown separately, in member list.
        const HOISTED = 1 << 0;
        /// Whether the role is managed. Managed roles cannot be edited or deleted.
        const MANAGED = 1 << 1;
        /// Whether the role is mentionable.
        const MENTIONABLE = 1 << 2;
        /// Whether the role is the default role for everyone.
        const DEFAULT = 1 << 3;
        /// If this role has an icon, this represents whether this icon should be displayed
        /// cumulatively with other icons of higher roles. The role icons to displayed for a given
        /// member, consist of the icon of the highest role the member has that has an icon and all
        /// roles below it that also have icons and have this flag set to true.
        const CUMULATIVE = 1 << 4;
    }
}

serde_for_bitflags!(u32: RoleFlags);