telexide/client/
context.rs

1use super::APIConnector;
2use parking_lot::RwLock;
3use std::sync::Arc;
4use typemap_rev::TypeMap;
5
6/// The context object is an utility object that gets passed to all event
7/// handlers, it provides access to the API client and to any custom data you
8/// have set in the data object.
9#[derive(Clone)]
10pub struct Context {
11    /// The API client, implementing the [`API`] trait
12    ///
13    /// [`API`]: ../api/trait.API.html
14    pub api: Arc<Box<APIConnector>>,
15    /// A clone of [`Client::data`], see its documentation for more detail
16    ///
17    /// [`Client::data`]: struct.Client.html#structfield.data
18    pub data: Arc<RwLock<TypeMap>>,
19}
20
21impl Context {
22    pub fn new(api: Arc<Box<APIConnector>>, data: Arc<RwLock<TypeMap>>) -> Self {
23        Self {
24            api,
25            data,
26        }
27    }
28}