1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
//! 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: //! //! ``` //! # async fn process_photo<T>(_: std::sync::Arc<T>) { } //! 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, connectors::Https}; //! async fn process_photo(context: Arc<contexts::Photo<Https>>) { //! 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, connectors::Https}; //! async fn process_photo(context: Arc<impl Photo<Https>>) { //! let photo = context.photo(); //! // .. //! } //! ``` //! //! [`contexts::Photo`]: ../struct.Photo.html //! [`contexts::EditedPhoto`]: ../struct.EditedPhoto.html //! [`fields::Photo`]: ./trait.Photo.html mod album; mod attachments; mod callback; mod context; mod messages; mod texts; pub use { album::Album, attachments::{Animation, Audio, Document, Location, Photo, Video}, callback::Callback, context::Context, messages::{EditedMessage, Forward, MediaMessage, Message}, texts::{AnyText, Caption, Text}, };