diff --git a/src/client/context.rs b/src/client/context.rs index 48b56241af0..ce3a2855462 100644 --- a/src/client/context.rs +++ b/src/client/context.rs @@ -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>, runner_tx: Sender, @@ -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>, + runner_tx: Sender, + shard_id: u64, + http: Arc, + ) -> 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>, + runner_tx: Sender, + shard_id: u64, + cache: Arc>, + ) -> 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>, + runner_tx: Sender, + 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. @@ -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));