pub struct CallbackDataCache { /* private fields */ }Expand description
A custom cache for storing the callback data of an ExtBot.
Internally, it keeps two mappings with fixed maximum size:
- One for mapping the data received in callback queries to the cached objects.
- One for mapping the IDs of received callback queries to the cached objects.
The second mapping allows manually dropping data cached for keyboards of messages sent via inline mode. If necessary, the least recently used items are evicted.
Implementations§
Source§impl CallbackDataCache
impl CallbackDataCache
Sourcepub fn new(maxsize: usize) -> Self
pub fn new(maxsize: usize) -> Self
Creates a new CallbackDataCache.
§Arguments
maxsize- Maximum number of items in each of the internal mappings.
Sourcepub fn load_persistence_data(&mut self, data: CdcData)
pub fn load_persistence_data(&mut self, data: CdcData)
Loads persisted data into the cache.
Sourcepub fn persistence_data(&self) -> CdcData
pub fn persistence_data(&self) -> CdcData
Returns the data that needs to be persisted.
Sourcepub fn process_keyboard(
&mut self,
reply_markup: &InlineKeyboardMarkup,
) -> InlineKeyboardMarkup
pub fn process_keyboard( &mut self, reply_markup: &InlineKeyboardMarkup, ) -> InlineKeyboardMarkup
Registers the reply markup in the cache.
If any of the buttons have callback_data, stores that data and builds a new keyboard
with the correspondingly replaced buttons. Otherwise, returns the original reply markup
unchanged.
Sourcepub fn extract_uuids(callback_data: &str) -> (&str, &str)
pub fn extract_uuids(callback_data: &str) -> (&str, &str)
Extracts keyboard uuid and button uuid from a raw callback data string.
The first 32 characters are the keyboard uuid, the rest is the button uuid.
Sourcepub fn process_message_value(&mut self, message: &mut Value) -> Option<String>
pub fn process_message_value(&mut self, message: &mut Value) -> Option<String>
Replaces the data in the inline keyboard attached to a raw JSON message value.
Works with Message.reply_markup being Option<Value> (the raw type from the
rust-tg-bot-raw crate).
Returns the keyboard UUID if resolution succeeded.
Sourcepub fn process_callback_query(&mut self, callback_query: &mut CallbackQuery)
pub fn process_callback_query(&mut self, callback_query: &mut CallbackQuery)
Replaces the data in the callback query (and attached message keyboard) with cached objects.
In place – modifies the passed CallbackQuery.
Sourcepub fn drop_data(
&mut self,
callback_query_id: &str,
) -> Result<(), InvalidCallbackData>
pub fn drop_data( &mut self, callback_query_id: &str, ) -> Result<(), InvalidCallbackData>
Deletes the data for the specified callback query.
§Errors
Returns Err if the callback query is not found in the cache.
Sourcepub fn clear_callback_data(&mut self, time_cutoff: Option<f64>)
pub fn clear_callback_data(&mut self, time_cutoff: Option<f64>)
Clears the stored callback data.
If time_cutoff is provided, only entries older than that UNIX timestamp are cleared.
Sourcepub fn clear_callback_queries(&mut self)
pub fn clear_callback_queries(&mut self)
Clears all stored callback query IDs.
Trait Implementations§
Source§impl Clone for CallbackDataCache
impl Clone for CallbackDataCache
Source§fn clone(&self) -> CallbackDataCache
fn clone(&self) -> CallbackDataCache
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more