Module traits

Module traits 

Source
Expand description

Traits for implementing a InMemoryCache with custom structs.

By default, the cache uses widely compatible default types that contain almost all fields that are present in the Discord API. Fields that are never used by the user will result in excess memory usage that will especially matter to big bots with a lot of cached data.

The traits in this module allow creating custom cached representations of Discord API models compatible with the InMemoryCache. They may be mixed with the default types provided by twilight, which also implement these traits.

However, as Discord extends its API models with new fields or changes the types, the trait definitions may change in minor crate releases to allow twilight to keep up with upstream API changes. Since not all fields are required for caching logic, this is not very likely to happen on a regular basis, but should be considered when deciding to opt for writing custom types.

Many traits require getters for certain types, which means they are used for caching logic. However, users generally won’t have to store all the fields. It is possible to return None or empty arrays on most of the methods if the data that is accessed is not stored in the custom implementation.

Traits§

CacheableChannel
Trait for a generic cached representation of a [Channel].
CacheableCurrentUser
Trait for a generic cached representation of a [CurrentUser].
CacheableEmoji
Trait for a generic cached representation of a [Emoji].
CacheableGuild
Trait for a generic cached representation of a [Guild].
CacheableGuildIntegration
Trait for a generic cached representation of a [GuildIntegration].
CacheableGuildScheduledEvent
Trait for a generic cached representation of a [GuildScheduledEvent].
CacheableMember
Trait for a generic cached representation of a [Member].
CacheableMessage
Trait for a generic cached representation of a [Message].
CacheableModels
Super-trait for the generic cached representations of Discord API models.
CacheablePresence
Trait for a generic cached representation of a [Presence].
CacheableRole
Trait for a generic cached representation of a [Role].
CacheableStageInstance
Trait for a generic cached representation of a [StageInstance].
CacheableSticker
Trait for a generic cached representation of a [Sticker].
CacheableUser
Trait for a generic cached representation of a [User].
CacheableVoiceState
Trait for a generic cached representation of a [VoiceState].