Skip to main content

CachedUser

Struct CachedUser 

Source
#[non_exhaustive]
pub struct CachedUser { pub id: UserId, pub username: CompactString, pub discriminator: u16, pub global_name: Option<CompactString>, pub avatar: Option<ImageHash>, pub bot: bool, pub system: bool, pub public_flags: Option<UserFlags>, /* private fields */ }
Expand description

A cached user (D-177): a [User] with its rarely set fields behind one box.

Every user has an ID, a username and usually a display name and an avatar; few have a banner, an accent color, an avatar decoration, collectibles or a primary guild. Those are kept in one allocation that only exists when one of them is set, and read through methods (banner, …). That keeps the user a user in many guilds shares with their members and messages at about two thirds of a [User].

The fields mean the same as in [User]; see the user object.

discord.js counterpart: User.

§Examples

use djs_cache::{Cache, CacheConfig, Limit};
use djs_model::{gateway::payload::GuildMemberAdd, id::UserId};

let cache = Cache::with_config(CacheConfig::builder().users(Limit::Unlimited).build());
let member: GuildMemberAdd = serde_json::from_str(
    r#"{"guild_id":"1","user":{"id":"2","username":"nelly","discriminator":"0",
        "global_name":"Nelly","avatar":null},"roles":[],"joined_at":null,
        "deaf":false,"mute":false,"flags":0}"#,
)?;
cache.update(&member);
let user = cache.users().get(UserId::new(2)).unwrap();
assert_eq!(user.display_name(), "Nelly");
assert_eq!(user.tag(), "nelly");
assert_eq!(user.banner(), None);

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§id: UserId§username: CompactString§discriminator: u16§global_name: Option<CompactString>§avatar: Option<ImageHash>§bot: bool§system: bool§public_flags: Option<UserFlags>

Implementations§

Source§

impl CachedUser

Source

pub fn banner(&self) -> Option<ImageHash>

The user’s banner (Nitro).

discord.js counterpart: User#banner.

Source

pub fn accent_color(&self) -> Option<u32>

The user’s banner color, as an RGB integer.

discord.js counterpart: User#accentColor.

Source

pub fn avatar_decoration_data(&self) -> Option<&AvatarDecorationData>

The user’s avatar decoration.

discord.js counterpart: User#avatarDecorationData.

Source

pub fn collectibles(&self) -> Option<&Collectibles>

The user’s collectibles (such as a nameplate).

discord.js counterpart: User#collectibles.

Source

pub fn primary_guild(&self) -> Option<&PrimaryGuild>

The guild whose tag the user displays.

discord.js counterpart: User#primaryGuild.

Source

pub fn display_name(&self) -> &str

The name to display: the global display name if set, otherwise the username.

discord.js counterpart: User#displayName.

Source

pub fn tag(&self) -> CompactString

The user’s tag: username#1234 for a legacy user, the username for a user with a unique username (discriminator 0).

discord.js counterpart: User#tag.

Trait Implementations§

Source§

impl Clone for CachedUser

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CachedUser

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for CachedUser

Source§

impl PartialEq for CachedUser

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for CachedUser

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.