Function collect

Source
pub fn collect<T: Send + 'static>(
    shard: &ShardMessenger,
    extractor: impl Fn(&Event) -> Option<T> + Send + Sync + 'static,
) -> impl Stream<Item = T>
Expand description

Fundamental collector function. All collector types in this module are just wrappers around this function.

Example: creating a collector stream over removed reactions

let stream = collect(shard, |event| match event {
    Event::ReactionRemove(event) => Some(event.reaction.clone()),
    _ => None,
});

stream
    .for_each(|reaction| async move {
        println!("{}: removed {}", reaction.channel_id, reaction.emoji);
    })
    .await;