diff options
| author | Austin Hellyer <[email protected]> | 2016-12-05 07:46:22 -0800 |
|---|---|---|
| committer | Austin Hellyer <[email protected]> | 2016-12-05 07:46:22 -0800 |
| commit | ccb9d16e5dbe965e5a604e1cb402cd3bc7de0df5 (patch) | |
| tree | b7eed1952ae14f215074452c3e3d1bc081a89b0a /src/client/context.rs | |
| parent | Add more Context docs+permission requirements (diff) | |
| download | serenity-ccb9d16e5dbe965e5a604e1cb402cd3bc7de0df5.tar.xz serenity-ccb9d16e5dbe965e5a604e1cb402cd3bc7de0df5.zip | |
Add a ShareMap across contexts
The context now exposes, through the Client, a `data` field, which can
be accessed safely across contexts. This allows for a custom "shared
state" without the need for (ab)using lazy-static.rs.
Refer to example 06 for an example on how to use shared data.
Diffstat (limited to 'src/client/context.rs')
| -rw-r--r-- | src/client/context.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/client/context.rs b/src/client/context.rs index 4fca519..af90447 100644 --- a/src/client/context.rs +++ b/src/client/context.rs @@ -6,6 +6,7 @@ use std::sync::{Arc, Mutex}; use super::gateway::Shard; use super::rest::{self, GuildPagination}; use super::login_type::LoginType; +use typemap::ShareMap; use ::utils::builder::{ CreateEmbed, CreateInvite, @@ -82,6 +83,11 @@ pub struct Context { /// /// [`on_message`]: struct.Client.html#method.on_message pub channel_id: Option<ChannelId>, + /// A clone of [`Client::data`]. Refer to its documentation for more + /// information. + /// + /// [`Client::data`]: struct.Client.html#method.data + pub data: Arc<Mutex<ShareMap>>, /// The associated shard which dispatched the event handler. /// /// Note that if you are sharding, in relevant terms, this is the shard @@ -101,9 +107,11 @@ impl Context { #[doc(hidden)] pub fn new(channel_id: Option<ChannelId>, shard: Arc<Mutex<Shard>>, + data: Arc<Mutex<ShareMap>>, login_type: LoginType) -> Context { Context { channel_id: channel_id, + data: data, shard: shard, login_type: login_type, } |