Skip to main content

Filter

Trait Filter 

Source
pub trait Filter:
    Send
    + Sync
    + 'static {
    // Required method
    fn check(&self, ctx: &Context) -> bool;
}
Expand description

A predicate evaluated against an incoming Context.

Filters are Send + Sync + 'static and cheap to clone, making them safe to share across tasks. Combine filters with FilterExt::and, FilterExt::or, and FilterExt::not.

Implement this trait to create custom filters:

use rustigram_bot::filter::Filter;
use rustigram_bot::Context;

#[derive(Clone)]
struct HasPhotoFilter;

impl Filter for HasPhotoFilter {
    fn check(&self, ctx: &Context) -> bool {
        ctx.message().and_then(|m| m.photo.as_ref()).is_some()
    }
}

Required Methods§

Source

fn check(&self, ctx: &Context) -> bool

Returns true if this filter matches the given context.

Implementors§