Skip to content

Commit

Permalink
Add different Context::news based on feature-set. (#492)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakelezz authored and arqunis committed Apr 6, 2019
1 parent b7a6fee commit 625b764
Showing 1 changed file with 48 additions and 3 deletions.
51 changes: 48 additions & 3 deletions src/client/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub struct Context {

impl Context {
/// Create a new Context to be passed to an event handler.
#[cfg(all(feature = "cache", feature = "http"))]
pub(crate) fn new(
data: Arc<RwLock<ShareMap>>,
runner_tx: Sender<InterMessage>,
Expand All @@ -62,13 +63,57 @@ impl Context {
shard: ShardMessenger::new(runner_tx),
shard_id,
data,
#[cfg(feature = "cache")]
cache,
#[cfg(feature = "http")]
http,
}
}

/// Create a new Context to be passed to an event handler.
#[cfg(all(not(feature = "cache"), feature = "http"))]
pub(crate) fn new(
data: Arc<RwLock<ShareMap>>,
runner_tx: Sender<InterMessage>,
shard_id: u64,
http: Arc<Http>,
) -> Context {
Context {
shard: ShardMessenger::new(runner_tx),
shard_id,
data,
http,
}
}

/// Create a new Context to be passed to an event handler.
#[cfg(all(feature = "cache", not(feature = "http")))]
pub(crate) fn new(
data: Arc<RwLock<ShareMap>>,
runner_tx: Sender<InterMessage>,
shard_id: u64,
cache: Arc<RwLock<Cache>>,
) -> Context {
Context {
shard: ShardMessenger::new(runner_tx),
shard_id,
data,
cache,
}
}

/// Create a new Context to be passed to an event handler.
#[cfg(all(not(feature = "cache"), not(feature = "http")))]
pub(crate) fn new(
data: Arc<RwLock<ShareMap>>,
runner_tx: Sender<InterMessage>,
shard_id: u64,
) -> Context {
Context {
shard: ShardMessenger::new(runner_tx),
shard_id,
data,
}
}

/// Edits the current user's profile settings.
///
/// Refer to `EditProfile`'s documentation for its methods.
Expand Down Expand Up @@ -114,7 +159,7 @@ impl Context {
map.insert("email", Value::String(email));
}
} else {
let user = http.get_current_user()?;
let user = self.http.get_current_user()?;

map.insert("username", Value::String(user.name));

Expand Down

0 comments on commit 625b764

Please sign in to comment.