Skip to main content

UpdateCache

Trait UpdateCache 

Source
pub trait UpdateCache: Sealed {
    type Previous;
}
Expand description

A gateway event payload the cache can apply, with the type of the previous state it returns (D-163).

Use it through Cache::update; for a whole [DispatchEvent] use Cache::update_dispatch. Every update borrows the event and copies what the cache keeps (D-161). The previous state is what the event replaced or removed, or nothing when the resource is disabled or the entry was not cached; for a guild it is the guild itself, not its roles, channels or members.

PayloadWhat it doesPrevious
[Ready]sets the current user; lists the guilds as unavailableOption<Arc<CurrentUser>>
[UserUpdate]replaces the current userOption<Arc<CurrentUser>>
[GuildCreate]caches the guild with its channels, roles, emojis, stickers and membersOption<Arc<CachedGuild>>
[GuildUpdate]updates the guild (and its roles, emojis, stickers if sent)Option<Arc<CachedGuild>>
[GuildDelete]removes the guild and everything in it, or marks it unavailable during an outageOption<Arc<CachedGuild>>
[ChannelCreate], [ChannelUpdate]caches the channel (threads are skipped)Option<Arc<Channel>>
[ChannelDelete]removes the channelOption<Arc<Channel>>
[ChannelPinsUpdate]sets the channel’s last pin timeOption<Arc<Channel>>
[GuildRoleCreate], [GuildRoleUpdate]caches the roleOption<Arc<Role>>
[GuildRoleDelete]removes the roleOption<Arc<Role>>
[GuildEmojisUpdate]replaces the guild’s emojisVec<Arc<Emoji>>
[GuildStickersUpdate]replaces the guild’s stickersVec<Arc<Sticker>>
[GuildMemberAdd]caches the member, counts it in the guildOption<Arc<CachedMember>>
[GuildMemberUpdate]updates (or adds) the memberOption<Arc<CachedMember>>
[GuildMemberRemove]removes the member, uncounts itOption<Arc<CachedMember>>
[GuildMembersChunk]caches the members (and their presences)Vec<Arc<CachedMember>> (those replaced)
[MessageCreate]caches the message (author as a user, its member as a member)Option<Arc<CachedMessage>>
[MessageUpdate]replaces a cached messageOption<Arc<CachedMessage>>
[MessageDelete]removes the messageOption<Arc<CachedMessage>>
[MessageDeleteBulk]removes the messagesVec<Arc<CachedMessage>>
[MessageReactionAdd], [MessageReactionRemove], [MessageReactionRemoveAll], [MessageReactionRemoveEmoji]updates a cached message’s reactionsOption<Arc<CachedMessage>>
[TypingStart]caches the typing member (in a guild)Option<Arc<CachedMember>>
[InteractionCreate]caches the interaction’s user and member, and the resolved users and members (not the resolved partial channels)Option<Arc<CachedMember>> (the interaction’s member)
[PresenceUpdate]caches the presence, or removes it when offlineOption<Arc<CachedPresence>>
[VoiceStateUpdate]caches the voice state, or removes it when the user left voiceOption<Arc<VoiceState>>
[ThreadCreate], [ThreadUpdate]caches the threadOption<Arc<Channel>>
[ThreadDelete]removes the thread and its messagesOption<Arc<Channel>>
[ThreadListSync]replaces the synced channels’ active threadsVec<Arc<Channel>>
[ThreadMembersUpdate]sets the thread’s member count; caches the added members as guild membersOption<Arc<Channel>>
[GuildScheduledEventCreate], [GuildScheduledEventUpdate], [GuildScheduledEventDelete]caches / removes the eventOption<Arc<GuildScheduledEvent>>
[StageInstanceCreate], [StageInstanceUpdate], [StageInstanceDelete]caches / removes the stage instanceOption<Arc<StageInstance>>
[GuildSoundboardSoundCreate], [GuildSoundboardSoundUpdate], [GuildSoundboardSoundDelete]caches / removes the soundOption<Arc<SoundboardSound>>
[GuildSoundboardSoundsUpdate]caches the soundsVec<Arc<SoundboardSound>> (those replaced)
[SoundboardSounds]replaces the guild’s soundsVec<Arc<SoundboardSound>>

Users seen in member events are cached too when Resource::User is enabled.

This trait is sealed: the cache implements it for the payloads it understands.

discord.js counterpart: the client’s internal actions (client.actions.GuildMemberUpdate, …), which also return the old and new state.

Required Associated Types§

Source

type Previous

The previous state this event returns.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl UpdateCache for ChannelCreate

Source§

type Previous = Option<Arc<Channel>>

Source§

impl UpdateCache for ChannelDelete

Source§

type Previous = Option<Arc<Channel>>

Source§

impl UpdateCache for ChannelPinsUpdate

Source§

type Previous = Option<Arc<Channel>>

Source§

impl UpdateCache for ChannelUpdate

Source§

type Previous = Option<Arc<Channel>>

Source§

impl UpdateCache for GuildCreate

Source§

impl UpdateCache for GuildDelete

Source§

impl UpdateCache for GuildEmojisUpdate

Source§

type Previous = Vec<Arc<Emoji>>

Source§

impl UpdateCache for GuildMemberAdd

Source§

impl UpdateCache for GuildMemberRemove

Source§

impl UpdateCache for GuildMemberUpdate

Source§

impl UpdateCache for GuildMembersChunk

Source§

impl UpdateCache for GuildRoleCreate

Source§

impl UpdateCache for GuildRoleDelete

Source§

impl UpdateCache for GuildRoleUpdate

Source§

impl UpdateCache for GuildScheduledEventCreate

Source§

type Previous = Option<Arc<GuildScheduledEvent>>

Source§

impl UpdateCache for GuildScheduledEventDelete

Source§

type Previous = Option<Arc<GuildScheduledEvent>>

Source§

impl UpdateCache for GuildScheduledEventUpdate

Source§

type Previous = Option<Arc<GuildScheduledEvent>>

Source§

impl UpdateCache for GuildSoundboardSoundCreate

Source§

type Previous = Option<Arc<SoundboardSound>>

Source§

impl UpdateCache for GuildSoundboardSoundDelete

Source§

type Previous = Option<Arc<SoundboardSound>>

Source§

impl UpdateCache for GuildSoundboardSoundUpdate

Source§

type Previous = Option<Arc<SoundboardSound>>

Source§

impl UpdateCache for GuildSoundboardSoundsUpdate

Source§

type Previous = Vec<Arc<SoundboardSound>>

Source§

impl UpdateCache for GuildStickersUpdate

Source§

type Previous = Vec<Arc<Sticker>>

Source§

impl UpdateCache for GuildUpdate

Source§

impl UpdateCache for InteractionCreate

Source§

impl UpdateCache for MessageCreate

Source§

impl UpdateCache for MessageDelete

Source§

impl UpdateCache for MessageDeleteBulk

Source§

impl UpdateCache for MessageReactionAdd

Source§

impl UpdateCache for MessageReactionRemove

Source§

impl UpdateCache for MessageReactionRemoveAll

Source§

impl UpdateCache for MessageReactionRemoveEmoji

Source§

impl UpdateCache for MessageUpdate

Source§

impl UpdateCache for PresenceUpdate

Source§

impl UpdateCache for Ready

Source§

type Previous = Option<Arc<CurrentUser>>

Source§

impl UpdateCache for SoundboardSounds

Source§

type Previous = Vec<Arc<SoundboardSound>>

Source§

impl UpdateCache for StageInstanceCreate

Source§

type Previous = Option<Arc<StageInstance>>

Source§

impl UpdateCache for StageInstanceDelete

Source§

type Previous = Option<Arc<StageInstance>>

Source§

impl UpdateCache for StageInstanceUpdate

Source§

type Previous = Option<Arc<StageInstance>>

Source§

impl UpdateCache for ThreadCreate

Source§

type Previous = Option<Arc<Channel>>

Source§

impl UpdateCache for ThreadDelete

Source§

type Previous = Option<Arc<Channel>>

Source§

impl UpdateCache for ThreadListSync

Source§

type Previous = Vec<Arc<Channel>>

Source§

impl UpdateCache for ThreadMembersUpdate

Source§

type Previous = Option<Arc<Channel>>

Source§

impl UpdateCache for ThreadUpdate

Source§

type Previous = Option<Arc<Channel>>

Source§

impl UpdateCache for TypingStart

Source§

impl UpdateCache for UserUpdate

Source§

type Previous = Option<Arc<CurrentUser>>

Source§

impl UpdateCache for VoiceStateUpdate

Source§

type Previous = Option<Arc<VoiceState>>

Implementors§