Struct twilight_cache_inmemory::iter::InMemoryCacheIter[][src]

pub struct InMemoryCacheIter<'a>(_);
Expand description

Interface to create iterators over various resources.

The created iterators will iterate over all entities of a resource across all channels and guilds.

The iteration order of all iterators are arbitrary.

Examples

Count the number of users in the cache whose username begins with “twi”:

use twilight_cache_inmemory::InMemoryCache;

let cache = InMemoryCache::new();

// later in the application...
let count = cache.iter()
    .users()
    .filter(|user| user.name.starts_with("twi"))
    .count();

println!("'twi' users: {}", count);

Potential inefficiency

Resource iterators over the entire cache are inefficient when the goal is to iterate over a resource in a specific guild. For example, when performing a task such as iterating over the members of a specific guild, retrieving the list of members via InMemoryCache::guild_members and then calling InMemoryCache::member for each item is more efficient. That might look like:

use twilight_cache_inmemory::InMemoryCache;
use twilight_model::id::GuildId;

let cache = InMemoryCache::new();

// later in the application...
let guild_id = GuildId::new(1).expect("non zero id");
let maybe_guild_members = cache.guild_members(guild_id);

if let Some(guild_members) = maybe_guild_members {
    for user_id in guild_members.iter() {
        if let Some(member) = cache.member(guild_id, *user_id) {
            println!(
                "member id {}'s nickname: {:?}",
                member.user_id(),
                member.nick(),
            );
        }
    }
}

Implementations

Immutable reference to the underlying cache.

Create an iterator over the emojis in the cache.

Create an iterator over the groups in the cache.

Create an iterator over the guilds in the cache.

Create an iterator over the guild channels in the cache.

This does not iterate over the channels in a particular guild but rather iterates over all GuildChannels in the cache.

Create an iterator over the integrations in the cache.

Create an iterator over the members across all guilds in the cache.

Create an iterator over the messages in the cache.

Create an iterator over the presences in the cache.

Create an iterator over the private channels in the cache.

Create an iterator over the roles in the cache.

Create an iterator over the stage instances in the cache.

Create an iterator over the stickers in the cache.

Create an iterator over the users in the cache.

Create an iterator over the voice states in the cache.

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.