[][src]Module tbot::contexts::fields

Traits for common context fields.

Suppose that you want to process users' photos whenever they send or edit one. You would like to abstract this as much as possible, like this:

let mut bot = tbot::from_env!("BOT_TOKEN").event_loop();
bot.photo(process_photo);
bot.edited_photo(process_photo);

However, in the first case we have contexts::Photo, but in the second one we have contexts::EditedPhoto. Luckily, they both implement fields::Photo, which allows accessing the photo field without caring about the exact update type. So, if you already have this handler:

use std::sync::Arc;
use tbot::{contexts};
async fn process_photo(context: Arc<contexts::Photo>) {
    let photo = &context.photo;
    // ..
}

You can generalize it to this one in order to also support contexts::EditedPhoto:

use std::sync::Arc;
use tbot::{contexts::fields::Photo};
async fn process_photo(context: Arc<impl Photo>) {
    let photo = context.photo();
    // ..
}

Traits

Album

A general trait for album items.

Animation

A general trait for animation messages.

AnyText

Unites Text and Caption.

Audio

A general trait for audio messages.

Callback

A general trait for callback updates.

Caption

A general trait for messages with a caption.

Context

A general trait for all contexts.

Document

A general trait for document messages.

EditedMessage

A general trait for edited messages.

Forward

A general trait for messages that can be a forward.

Location

A general trait for location messages.

MediaMessage

A general trait for all non-service messages.

Message

A general trait for all message contexts.

Photo

A general trait for photo messages.

Text

A general trait for text messages.

Video

A general trait for video messages.