aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2018-08-07 09:24:07 -0700
committerZeyla Hellyer <[email protected]>2018-08-07 09:25:06 -0700
commit39bb75cc6759ceb972c0caca0b03c7971a445eb8 (patch)
tree343d97399ea597804f0cd30016034c4adb8efebe /src
parentFix some documentation spacing (diff)
downloadserenity-39bb75cc6759ceb972c0caca0b03c7971a445eb8.tar.xz
serenity-39bb75cc6759ceb972c0caca0b03c7971a445eb8.zip
Fix compilation + tests on certain feature combos
On certain feature combinations, compilation and tests would not function correctly. This commit goes through a number of feature combinations and gates some tests behind the required features and fixes other compilation errors.
Diffstat (limited to 'src')
-rw-r--r--src/client/bridge/gateway/shard_messenger.rs10
-rw-r--r--src/client/dispatch.rs1
-rw-r--r--src/http/mod.rs2
-rw-r--r--src/internal/macros.rs11
-rw-r--r--src/lib.rs17
-rw-r--r--src/model/channel/mod.rs42
-rw-r--r--src/model/misc.rs130
7 files changed, 132 insertions, 81 deletions
diff --git a/src/client/bridge/gateway/shard_messenger.rs b/src/client/bridge/gateway/shard_messenger.rs
index 6d625b6..a3b5918 100644
--- a/src/client/bridge/gateway/shard_messenger.rs
+++ b/src/client/bridge/gateway/shard_messenger.rs
@@ -147,9 +147,19 @@ impl ShardMessenger {
/// #
/// # let mut shard = Shard::new(mutex.clone(), mutex, [0, 1]).unwrap();
/// #
+ /// # #[cfg(feature = "model")]
/// use serenity::model::gateway::Game;
+ /// # #[cfg(not(feature = "model"))]
+ /// use serenity::model::gateway::{Game, GameType};
///
+ /// # #[cfg(feature = "model")]
/// shard.set_game(Some(Game::playing("Heroes of the Storm")));
+ /// # #[cfg(not(feature = "model"))]
+ /// shard.set_game(Some(Game {
+ /// kind: GameType::Playing,
+ /// name: "Heroes of the Storm".to_owned(),
+ /// url: None,
+ /// }));
/// # Ok(())
/// # }
/// #
diff --git a/src/client/dispatch.rs b/src/client/dispatch.rs
index b81b901..7a9e725 100644
--- a/src/client/dispatch.rs
+++ b/src/client/dispatch.rs
@@ -97,6 +97,7 @@ pub(crate) fn dispatch<H: EventHandler + Send + Sync + 'static>(
}
#[cfg(not(feature = "framework"))]
+#[allow(unused_mut)]
pub(crate) fn dispatch<H: EventHandler + Send + Sync + 'static>(
event: DispatchEvent,
data: &Arc<Mutex<ShareMap>>,
diff --git a/src/http/mod.rs b/src/http/mod.rs
index 51d89aa..d9454c2 100644
--- a/src/http/mod.rs
+++ b/src/http/mod.rs
@@ -601,7 +601,7 @@ pub fn delete_role(guild_id: u64, role_id: u64) -> Result<()> {
/// Deletes a webhook given its Id:
///
/// ```rust,no_run
-/// use serenity::{Client, http};
+/// use serenity::http;
/// use std::env;
///
/// // Due to the `delete_webhook` function requiring you to authenticate, you
diff --git a/src/internal/macros.rs b/src/internal/macros.rs
index 31b6b7d..a03e9bd 100644
--- a/src/internal/macros.rs
+++ b/src/internal/macros.rs
@@ -1,6 +1,6 @@
//! A set of macros for easily working with internals.
-#[cfg(feature = "http")]
+#[cfg(feature = "model")]
macro_rules! request_client {
() => {{
use hyper::net::HttpsConnector;
@@ -59,15 +59,6 @@ macro_rules! feature_cache {
}
}
-#[cfg(all(feature = "client", not(feature = "framework")))]
-macro_rules! feature_framework {
- ($enabled:block else $disabled:block) => {
- {
- $disabled
- }
- }
-}
-
macro_rules! enum_number {
($name:ident { $($variant:ident, )* }) => {
impl ::serde::Serialize for $name {
diff --git a/src/lib.rs b/src/lib.rs
index 0e4577d..e933af0 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -32,8 +32,10 @@
//! ```rust,no_run
//! #[macro_use] extern crate serenity;
//!
-//! use serenity::client::Client;
-//! use serenity::prelude::EventHandler;
+//! # #[cfg(all(feature = "client", feature = "standard_framework"))]
+//! # mod inner {
+//! #
+//! use serenity::client::{Client, EventHandler};
//! use serenity::framework::standard::StandardFramework;
//! use std::env;
//!
@@ -45,6 +47,7 @@
//! // Login with a bot token from the environment
//! let mut client = Client::new(&env::var("DISCORD_TOKEN").expect("token"), Handler)
//! .expect("Error creating client");
+//!
//! client.with_framework(StandardFramework::new()
//! .configure(|c| c.prefix("~")) // set the bot's prefix to "~"
//! .cmd("ping", ping));
@@ -58,6 +61,13 @@
//! command!(ping(_context, message) {
//! let _ = message.reply("Pong!");
//! });
+//! #
+//! # }
+//! #
+//! # #[cfg(all(feature = "client", feature = "standard_framework"))]
+//! # fn main() { inner::main() }
+//! # #[cfg(not(all(feature = "client", feature = "standard_framework")))]
+//! # fn main() {}
//! ```
//!
//! ### Full Examples
@@ -100,10 +110,12 @@
#[macro_use]
extern crate bitflags;
+#[allow(unused_imports)]
#[macro_use]
extern crate log;
#[macro_use]
extern crate serde_derive;
+#[allow(unused_imports)]
#[macro_use]
extern crate serde_json;
@@ -140,6 +152,7 @@ extern crate typemap;
#[cfg(feature = "evzht9h3nznqzwl")]
extern crate evzht9h3nznqzwl as websocket;
+#[allow(unused_imports)]
#[cfg(test)]
#[macro_use]
extern crate matches;
diff --git a/src/model/channel/mod.rs b/src/model/channel/mod.rs
index 9b350e5..5ba9a87 100644
--- a/src/model/channel/mod.rs
+++ b/src/model/channel/mod.rs
@@ -69,9 +69,13 @@ impl Channel {
///
/// ```rust,no_run
/// # extern crate serenity;
+ /// #
/// # use self::serenity::model::id::ChannelId;
+ /// #
+ /// # #[cfg(feature = "model")]
/// # fn main() {
- /// # let channel = ChannelId(0).get().unwrap();
+ /// # let channel = ChannelId(0).get().unwrap();
+ /// #
/// match channel.group() {
/// Some(group_lock) => {
/// if let Some(ref name) = group_lock.read().name {
@@ -82,7 +86,11 @@ impl Channel {
/// },
/// None => { println!("It's not a group!"); },
/// }
+ /// #
/// # }
+ /// #
+ /// # #[cfg(not(feature = "model"))]
+ /// fn main() {}
/// ```
pub fn group(self) -> Option<Arc<RwLock<Group>>> {
match self {
@@ -103,16 +111,24 @@ impl Channel {
///
/// ```rust,no_run
/// # extern crate serenity;
+ /// #
/// # use self::serenity::model::id::ChannelId;
+ /// #
+ /// # #[cfg(feature = "model")]
/// # fn main() {
- /// let channel = ChannelId(0).get().unwrap();
+ /// # let channel = ChannelId(0).get().unwrap();
+ /// #
/// match channel.guild() {
/// Some(guild_lock) => {
/// println!("It's a guild named {}!", guild_lock.read().name);
/// },
/// None => { println!("It's not a guild!"); },
/// }
+ /// #
/// # }
+ /// #
+ /// # #[cfg(not(feature = "model"))]
+ /// fn main() {}
/// ```
pub fn guild(self) -> Option<Arc<RwLock<GuildChannel>>> {
match self {
@@ -133,9 +149,13 @@ impl Channel {
///
/// ```rust,no_run
/// # extern crate serenity;
+ /// #
/// # use self::serenity::model::id::ChannelId;
+ /// #
+ /// # #[cfg(feature = "model")]
/// # fn main() {
- /// # let channel = ChannelId(0).get().unwrap();
+ /// # let channel = ChannelId(0).get().unwrap();
+ /// #
/// match channel.private() {
/// Some(private_lock) => {
/// let private = private_lock.read();
@@ -145,7 +165,11 @@ impl Channel {
/// },
/// None => { println!("It's not a private channel!"); },
/// }
+ /// #
/// # }
+ /// #
+ /// # #[cfg(not(feature = "model"))]
+ /// fn main() {}
/// ```
pub fn private(self) -> Option<Arc<RwLock<PrivateChannel>>> {
match self {
@@ -166,16 +190,24 @@ impl Channel {
///
/// ```rust,no_run
/// # extern crate serenity;
+ /// #
/// # use self::serenity::model::id::ChannelId;
+ /// #
+ /// # #[cfg(feature = "model")]
/// # fn main() {
/// # let channel = ChannelId(0).get().unwrap();
+ /// #
/// match channel.category() {
/// Some(category_lock) => {
/// println!("It's a category named {}!", category_lock.read().name);
/// },
/// None => { println!("It's not a category!"); },
/// }
+ /// #
/// # }
+ /// #
+ /// # #[cfg(not(feature = "model"))]
+ /// fn main() {}
/// ```
pub fn category(self) -> Option<Arc<RwLock<ChannelCategory>>> {
match self {
@@ -674,8 +706,8 @@ pub enum PermissionOverwriteType {
#[cfg(test)]
mod test {
- #[cfg(feature = "utils")]
- mod utils {
+ #[cfg(all(feature = "model", feature = "utils"))]
+ mod model_utils {
use model::prelude::*;
use parking_lot::RwLock;
use std::collections::HashMap;
diff --git a/src/model/misc.rs b/src/model/misc.rs
index 62a002a..5c0825a 100644
--- a/src/model/misc.rs
+++ b/src/model/misc.rs
@@ -312,9 +312,6 @@ pub struct Maintenance {
#[cfg(test)]
mod test {
use model::prelude::*;
- use parking_lot::RwLock;
- use std::sync::Arc;
- use utils::Colour;
#[test]
fn test_formatters() {
@@ -326,65 +323,72 @@ mod test {
}
#[cfg(feature = "utils")]
- #[test]
- fn test_mention() {
- let channel = Channel::Guild(Arc::new(RwLock::new(GuildChannel {
- bitrate: None,
- category_id: None,
- guild_id: GuildId(1),
- kind: ChannelType::Text,
- id: ChannelId(4),
- last_message_id: None,
- last_pin_timestamp: None,
- name: "a".to_string(),
- permission_overwrites: vec![],
- position: 1,
- topic: None,
- user_limit: None,
- nsfw: false,
- })));
- let emoji = Emoji {
- animated: false,
- id: EmojiId(5),
- name: "a".to_string(),
- managed: true,
- require_colons: true,
- roles: vec![],
- };
- let role = Role {
- id: RoleId(2),
- colour: Colour::ROSEWATER,
- hoist: false,
- managed: false,
- mentionable: false,
- name: "fake role".to_string(),
- permissions: Permissions::empty(),
- position: 1,
- };
- let user = User {
- id: UserId(6),
- avatar: None,
- bot: false,
- discriminator: 4132,
- name: "fake".to_string(),
- };
- let member = Member {
- deaf: false,
- guild_id: GuildId(2),
- joined_at: None,
- mute: false,
- nick: None,
- roles: vec![],
- user: Arc::new(RwLock::new(user.clone())),
- };
-
- assert_eq!(ChannelId(1).mention(), "<#1>");
- assert_eq!(channel.mention(), "<#4>");
- assert_eq!(emoji.mention(), "<:a:5>");
- assert_eq!(member.mention(), "<@6>");
- assert_eq!(role.mention(), "<@&2>");
- assert_eq!(role.id.mention(), "<@&2>");
- assert_eq!(user.mention(), "<@6>");
- assert_eq!(user.id.mention(), "<@6>");
+ mod utils {
+ use model::prelude::*;
+ use parking_lot::RwLock;
+ use std::sync::Arc;
+ use utils::Colour;
+
+ #[test]
+ fn test_mention() {
+ let channel = Channel::Guild(Arc::new(RwLock::new(GuildChannel {
+ bitrate: None,
+ category_id: None,
+ guild_id: GuildId(1),
+ kind: ChannelType::Text,
+ id: ChannelId(4),
+ last_message_id: None,
+ last_pin_timestamp: None,
+ name: "a".to_string(),
+ permission_overwrites: vec![],
+ position: 1,
+ topic: None,
+ user_limit: None,
+ nsfw: false,
+ })));
+ let emoji = Emoji {
+ animated: false,
+ id: EmojiId(5),
+ name: "a".to_string(),
+ managed: true,
+ require_colons: true,
+ roles: vec![],
+ };
+ let role = Role {
+ id: RoleId(2),
+ colour: Colour::ROSEWATER,
+ hoist: false,
+ managed: false,
+ mentionable: false,
+ name: "fake role".to_string(),
+ permissions: Permissions::empty(),
+ position: 1,
+ };
+ let user = User {
+ id: UserId(6),
+ avatar: None,
+ bot: false,
+ discriminator: 4132,
+ name: "fake".to_string(),
+ };
+ let member = Member {
+ deaf: false,
+ guild_id: GuildId(2),
+ joined_at: None,
+ mute: false,
+ nick: None,
+ roles: vec![],
+ user: Arc::new(RwLock::new(user.clone())),
+ };
+
+ assert_eq!(ChannelId(1).mention(), "<#1>");
+ assert_eq!(channel.mention(), "<#4>");
+ assert_eq!(emoji.mention(), "<:a:5>");
+ assert_eq!(member.mention(), "<@6>");
+ assert_eq!(role.mention(), "<@&2>");
+ assert_eq!(role.id.mention(), "<@&2>");
+ assert_eq!(user.mention(), "<@6>");
+ assert_eq!(user.id.mention(), "<@6>");
+ }
}
}