From 8e296940b7e40879dcfbb185282b906804ba7e3d Mon Sep 17 00:00:00 2001 From: Zeyla Hellyer Date: Fri, 18 Aug 2017 15:52:07 -0700 Subject: Move the Framework trait to the framework --- src/client/dispatch.rs | 2 +- src/client/mod.rs | 4 ++-- src/framework/mod.rs | 19 ++++++++++++++++++- src/lib.rs | 21 --------------------- 4 files changed, 21 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/client/dispatch.rs b/src/client/dispatch.rs index ad3660e..cb33cb1 100644 --- a/src/client/dispatch.rs +++ b/src/client/dispatch.rs @@ -12,7 +12,7 @@ use chrono::{Timelike, Utc}; use tokio_core::reactor::Handle; #[cfg(feature = "framework")] -use Framework; +use framework::Framework; #[cfg(feature = "cache")] use super::CACHE; diff --git a/src/client/mod.rs b/src/client/mod.rs index 69d3903..619653c 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -37,7 +37,7 @@ pub use CACHE; use self::dispatch::dispatch; use std::sync::{self, Arc}; -use std::sync::atomic::{AtomicBool, Ordering, ATOMIC_BOOL_INIT}; +use std::sync::atomic::{ATOMIC_BOOL_INIT, AtomicBool, Ordering}; use parking_lot::Mutex; use tokio_core::reactor::Core; use futures; @@ -52,7 +52,7 @@ use internal::ws_impl::ReceiverExt; use model::event::*; #[cfg(feature = "framework")] -use Framework; +use framework::Framework; static HANDLE_STILL: AtomicBool = ATOMIC_BOOL_INIT; diff --git a/src/framework/mod.rs b/src/framework/mod.rs index 98f7d40..c95c160 100644 --- a/src/framework/mod.rs +++ b/src/framework/mod.rs @@ -888,7 +888,7 @@ impl BuiltinFramework { } } -impl ::Framework for BuiltinFramework { +impl Framework for BuiltinFramework { fn dispatch(&mut self, mut context: Context, message: Message, tokio_handle: &Handle) { let res = command::positions(&mut context, &message, &self.configuration); @@ -1025,3 +1025,20 @@ impl ::Framework for BuiltinFramework { #[cfg(feature = "builtin_framework")] fn initialized(&self) -> bool { self.initialized } } + +/// This trait allows for serenity to either use its builtin framework, or yours. +/// +/// When implementing, be sure to use `tokio_handle.spawn_fn(|| ...; Ok())` when dispatching +/// commands. +/// +/// Note that you may see some other methods in here as well, but they're meant to be internal only +/// for the builtin framework. +#[cfg(feature = "framework")] +pub trait Framework { + fn dispatch(&mut self, Context, Message, &Handle); + + #[cfg(feature = "builtin_framework")] + fn update_current_user(&mut self, UserId, bool) {} + #[cfg(feature = "builtin_framework")] + fn initialized(&self) -> bool { false } +} diff --git a/src/lib.rs b/src/lib.rs index a9c4cc2..b8d4c06 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -171,10 +171,6 @@ pub(crate) use cache::CacheEventsImpl; #[cfg(feature = "cache")] use std::sync::RwLock; -use model::{Message, UserId}; -use client::Context; -use tokio_core::reactor::Handle; - #[cfg(feature = "cache")] lazy_static! { /// A mutable and lazily-initialized static binding. It can be accessed @@ -213,20 +209,3 @@ lazy_static! { /// [cache module documentation]: cache/index.html pub static ref CACHE: RwLock = RwLock::new(Cache::default()); } - -/// This trait allows for serenity to either use its builtin framework, or yours. -/// -/// When implementing, be sure to use `tokio_handle.spawn_fn(|| ...; Ok())` when dispatching -/// commands. -/// -/// Note that you may see some other methods in here as well, but they're meant to be internal only -/// for the builtin framework. -#[cfg(feature = "framework")] -pub trait Framework { - fn dispatch(&mut self, Context, Message, &Handle); - - #[cfg(feature = "builtin_framework")] - fn update_current_user(&mut self, UserId, bool) {} - #[cfg(feature = "builtin_framework")] - fn initialized(&self) -> bool { false } -} -- cgit v1.2.3