aboutsummaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-11-15 11:36:53 -0800
committerAustin Hellyer <[email protected]>2016-11-15 11:36:53 -0800
commit5ccfaaa3b1a030b1fd0dcd364bdae001347d36e4 (patch)
tree7cf531e4790109d6d7edd26bc5b483378d5ba5ac /src/utils
parentEmbed Author: everything but 'name' is optional (diff)
downloadserenity-5ccfaaa3b1a030b1fd0dcd364bdae001347d36e4.tar.xz
serenity-5ccfaaa3b1a030b1fd0dcd364bdae001347d36e4.zip
Add state/framework/etc. conditional compile flags
This adds conditional compilation for the following features, in addition to the voice conditional compilation flag: - extras (message builder) - framework - methods - state These 4 are enabled _by default_, while the `voice` feature flag is disabled. Disabling the state will allow incredibly low-memory bots.
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/builder/edit_role.rs14
-rw-r--r--src/utils/macros.rs300
-rw-r--r--src/utils/mod.rs90
3 files changed, 321 insertions, 83 deletions
diff --git a/src/utils/builder/edit_role.rs b/src/utils/builder/edit_role.rs
index d1e2c0e..f87d22e 100644
--- a/src/utils/builder/edit_role.rs
+++ b/src/utils/builder/edit_role.rs
@@ -93,12 +93,18 @@ impl Default for EditRole {
///
/// [general permissions set]: ../model/permissions/fn.general.html
fn default() -> EditRole {
- EditRole(ObjectBuilder::new()
+ let mut map = ObjectBuilder::new()
.insert("color", 10070709)
.insert("hoist", false)
.insert("mentionable", false)
- .insert("name", String::from("new role"))
- .insert("permissions", permissions::general().bits())
- .insert("position", 1))
+ .insert("name", "new role".to_owned());
+
+ feature_extras_enabled! {{
+ map = map.insert("permissions", permissions::general().bits());
+ }}
+
+ map = map.insert("position", 1);
+
+ EditRole(map)
}
}
diff --git a/src/utils/macros.rs b/src/utils/macros.rs
new file mode 100644
index 0000000..34cfaa4
--- /dev/null
+++ b/src/utils/macros.rs
@@ -0,0 +1,300 @@
+macro_rules! request {
+ ($route:expr, $method:ident($body:expr), $url:expr, $($rest:tt)*) => {{
+ let client = HyperClient::new();
+ try!(request($route, || client
+ .$method(&format!(api!($url), $($rest)*))
+ .body(&$body)))
+ }};
+ ($route:expr, $method:ident($body:expr), $url:expr) => {{
+ let client = HyperClient::new();
+ try!(request($route, || client
+ .$method(api!($url))
+ .body(&$body)))
+ }};
+ ($route:expr, $method:ident, $url:expr, $($rest:tt)*) => {{
+ let client = HyperClient::new();
+ try!(request($route, || client
+ .$method(&format!(api!($url), $($rest)*))))
+ }};
+ ($route:expr, $method:ident, $url:expr) => {{
+ let client = HyperClient::new();
+ try!(request($route, || client
+ .$method(api_concat!($url))))
+ }};
+}
+
+macro_rules! cdn_concat {
+ ($e:expr) => {
+ concat!("https://cdn.discordapp.com", $e)
+ }
+}
+macro_rules! api {
+ ($e:expr) => {
+ concat!("https://discordapp.com/api/v6", $e)
+ };
+ ($e:expr, $($rest:tt)*) => {
+ format!(api!($e), $($rest)*)
+ };
+}
+
+macro_rules! api_concat {
+ ($e:expr) => {
+ concat!("https://discordapp.com/api/v6", $e)
+ }
+}
+macro_rules! status_concat {
+ ($e:expr) => {
+ concat!("https://status.discordapp.com/api/v2", $e)
+ }
+}
+
+// Enable/disable check for extras
+macro_rules! feature_extras {
+ ($enabled:block) => {
+ {
+ feature_extras_enabled! {{
+ $enabled
+ }}
+ }
+ };
+ ($enabled:block $disabled:block) => {
+ {
+ feature_extras_enabled! {{
+ $enabled
+ }}
+
+ feature_extras_disabled! {{
+ $disabled
+ }}
+ }
+ };
+}
+
+#[cfg(feature = "extras")]
+macro_rules! feature_extras_enabled {
+ ($enabled:block) => {{
+ {
+ $enabled
+ }
+ }}
+}
+
+#[cfg(not(feature = "extras"))]
+macro_rules! feature_extras_enabled {
+ ($enabled:block) => {}
+}
+
+#[cfg(feature = "extras")]
+macro_rules! feature_extras_disabled {
+ ($disabled:block) => {}
+}
+
+#[cfg(not(feature = "extras"))]
+macro_rules! feature_extras_disabled {
+ ($disabled:block) => {
+ {
+ $disabled
+ }
+ }
+}
+
+// Enable/disable check for framework
+macro_rules! feature_framework {
+ ($enabled:block) => {
+ {
+ feature_framework_enabled! {{
+ $enabled
+ }}
+ }
+ };
+ ($enabled:block $disabled:block) => {
+ {
+ feature_framework_enabled! {{
+ $enabled
+ }}
+
+ feature_framework_disabled! {{
+ $disabled
+ }}
+ }
+ };
+}
+
+#[cfg(feature = "framework")]
+macro_rules! feature_framework_enabled {
+ ($enabled:block) => {
+ {
+ $enabled
+ }
+ }
+}
+
+#[cfg(not(feature = "framework"))]
+macro_rules! feature_framework_enabled {
+ ($enabled:block) => {}
+}
+
+#[cfg(feature = "framework")]
+macro_rules! feature_framework_disabled {
+ ($disabled:block) => {}
+}
+
+#[cfg(not(feature = "framework"))]
+macro_rules! feature_framework_disabled {
+ ($disabled:block) => {
+ {
+ $disabled
+ }
+ }
+}
+
+// Enable/disable check for methods
+macro_rules! feature_methods {
+ ($enabled:block) => {
+ {
+ feature_methods_enabled! {{
+ $enabled
+ }}
+ }
+ };
+ ($enabled:block $disabled:block) => {
+ {
+ feature_methods_enabled! {{
+ $enabled
+ }}
+
+ feature_methods_disabled! {{
+ $disabled
+ }}
+ }
+ };
+}
+
+#[cfg(feature = "methods")]
+macro_rules! feature_methods_enabled {
+ ($enabled:block) => {
+ {
+ $enabled
+ }
+ }
+}
+
+#[cfg(not(feature = "methods"))]
+macro_rules! feature_methods_enabled {
+ ($enabled:block) => {}
+}
+
+#[cfg(feature = "methods")]
+macro_rules! feature_methods_disabled {
+ ($disabled:block) => {}
+}
+
+#[cfg(not(feature = "methods"))]
+macro_rules! feature_methods_disabled {
+ ($disabled:block) => {
+ {
+ $disabled
+ }
+ }
+}
+
+// Enable/disable check for state
+#[cfg(feature = "state")]
+macro_rules! feature_state {
+ ($enabled:block) => {
+ {
+ feature_state_enabled! {{
+ $enabled
+ }}
+ }
+ };
+ ($enabled:block else $disabled:block) => {
+ {
+ feature_state_enabled! {{
+ $enabled
+ }}
+
+ feature_state_disabled! {{
+ $disabled
+ }}
+ }
+ };
+}
+
+#[cfg(feature = "state")]
+macro_rules! feature_state_enabled {
+ ($enabled:block) => {
+ {
+ $enabled
+ }
+ }
+}
+
+#[cfg(not(feature = "state"))]
+macro_rules! feature_state_enabled {
+ ($enabled:block) => {}
+}
+
+#[cfg(feature = "state")]
+macro_rules! feature_state_disabled {
+ ($disabled:block) => {}
+}
+
+#[cfg(not(feature = "state"))]
+macro_rules! feature_state_disabled {
+ ($disabled:block) => {
+ {
+ $disabled
+ }
+ }
+}
+
+// Enable/disable check for voice
+macro_rules! feature_voice {
+ ($enabled:block) => {
+ {
+ feature_voice_enabled! {{
+ $enabled
+ }}
+ }
+ };
+ ($enabled:block $disabled:block) => {
+ {
+ feature_voice_enabled! {{
+ $enabled
+ }}
+
+ feature_voice_disabled! {{
+ $disabled
+ }}
+ }
+ };
+}
+
+#[cfg(feature = "voice")]
+macro_rules! feature_voice_enabled {
+ ($enabled:block) => {
+ {
+ $enabled
+ }
+ }
+}
+
+#[cfg(not(feature = "voice"))]
+macro_rules! feature_voice_enabled {
+ ($enabled:block) => {}
+}
+
+#[cfg(feature = "voice")]
+macro_rules! feature_voice_disabled {
+ ($disabled:block) => {}
+}
+
+#[cfg(not(feature = "voice"))]
+macro_rules! feature_voice_disabled {
+ ($disabled:block) => {
+ {
+ $disabled
+ }
+ }
+}
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
index 28d18f1..ccf7787 100644
--- a/src/utils/mod.rs
+++ b/src/utils/mod.rs
@@ -1,8 +1,18 @@
//! A set of utilities to help with common use cases that are not required to
//! fully use the library.
+#[macro_use]
+pub mod macros;
+
pub mod builder;
+mod colour;
+
+#[cfg(feature = "extras")]
+mod message_builder;
+
+pub use self::colour::Colour;
+
use base64;
use std::ffi::OsStr;
use std::fs::File;
@@ -10,10 +20,7 @@ use std::io::Read;
use std::path::Path;
use ::internal::prelude::*;
-mod colour;
-mod message_builder;
-
-pub use self::colour::Colour;
+#[cfg(feature = "extras")]
pub use self::message_builder::MessageBuilder;
macro_rules! cdn_concat {
@@ -83,81 +90,6 @@ pub fn into_array(value: Value) -> Result<Vec<Value>> {
}
}
-macro_rules! request {
- ($route:expr, $method:ident($body:expr), $url:expr, $($rest:tt)*) => {{
- let client = HyperClient::new();
- try!(request($route, || client
- .$method(&format!(api!($url), $($rest)*))
- .body(&$body)))
- }};
- ($route:expr, $method:ident($body:expr), $url:expr) => {{
- let client = HyperClient::new();
- try!(request($route, || client
- .$method(api!($url))
- .body(&$body)))
- }};
- ($route:expr, $method:ident, $url:expr, $($rest:tt)*) => {{
- let client = HyperClient::new();
- try!(request($route, || client
- .$method(&format!(api!($url), $($rest)*))))
- }};
- ($route:expr, $method:ident, $url:expr) => {{
- let client = HyperClient::new();
- try!(request($route, || client
- .$method(api_concat!($url))))
- }};
-}
-
-// Enable/disable check for voice
-macro_rules! feature_voice {
- ($enabled:block) => {
- {
- feature_voice_enabled! {{
- $enabled
- }}
- }
- };
- ($enabled:block $disabled:block) => {
- {
- feature_voice_enabled! {{
- $enabled
- }}
-
- feature_voice_disabled! {{
- $disabled
- }}
- }
- };
-}
-
-#[cfg(feature="voice")]
-macro_rules! feature_voice_enabled {
- ($enabled:block) => {
- {
- $enabled
- }
- }
-}
-
-#[cfg(not(feature="voice"))]
-macro_rules! feature_voice_enabled {
- ($enabled:block) => {}
-}
-
-#[cfg(feature="voice")]
-macro_rules! feature_voice_disabled {
- ($disabled:block) => {}
-}
-
-#[cfg(not(feature="voice"))]
-macro_rules! feature_voice_disabled {
- ($disabled:block) => {
- {
- $disabled
- }
- }
-}
-
/// Retrieves the "code" part of an [invite][`RichInvite`] out of a URL.
///
/// # Examples