aboutsummaryrefslogtreecommitdiff
path: root/src/model/channel
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-12-16 08:39:36 -0800
committerZeyla Hellyer <[email protected]>2017-12-16 08:45:26 -0800
commitbcd16dddb8cc3086a13524c79676f3a8bebbc524 (patch)
tree42d254fb4738df957c4b7d9e5766d1cb5bd47323 /src/model/channel
parentFix guild deserialization tests (diff)
downloadserenity-bcd16dddb8cc3086a13524c79676f3a8bebbc524.tar.xz
serenity-bcd16dddb8cc3086a13524c79676f3a8bebbc524.zip
Break up the model module
The `model` module has historically been one giant module re-exporting all of the model types, which is somewhere around 100 types. This can be a lot to look at for a new user and somewhat overwhelming, especially with a large number of fine-grained imports from the module. The module is now neatly split up into submodules, mostly like it has been internally since the early versions of the library. The submodules are: - application - channel - error - event - gateway - guild - id - invite - misc - permissions - prelude - user - voice - webhook Each submodule contains types that are "owned" by the module. For example, the `guild` submodule contains, but not limited to, Emoji, AuditLogsEntry, Role, and Member. `channel` contains, but not limited to, Attachment, Embed, Message, and Reaction. Upgrade path: Instead of glob importing the models via `use serenity::model::*;`, instead glob import via the prelude: ```rust use serenity::model::prelude::*; ``` Instead of importing from the root model module: ```rust use serenity::model::{Guild, Message, OnlineStatus, Role, User}; ``` instead import from the submodules like so: ```rust use serenity::model::channel::Message; use serenity::model::guild::{Guild, Role}; use serenity::model::user::{OnlineStatus, User}; ```
Diffstat (limited to 'src/model/channel')
-rw-r--r--src/model/channel/attachment.rs3
-rw-r--r--src/model/channel/channel_category.rs2
-rw-r--r--src/model/channel/channel_id.rs6
-rw-r--r--src/model/channel/embed.rs2
-rw-r--r--src/model/channel/group.rs2
-rw-r--r--src/model/channel/guild_channel.rs34
-rw-r--r--src/model/channel/message.rs6
-rw-r--r--src/model/channel/mod.rs4
-rw-r--r--src/model/channel/private_channel.rs2
-rw-r--r--src/model/channel/reaction.rs6
10 files changed, 33 insertions, 34 deletions
diff --git a/src/model/channel/attachment.rs b/src/model/channel/attachment.rs
index 1836498..a9c625b 100644
--- a/src/model/channel/attachment.rs
+++ b/src/model/channel/attachment.rs
@@ -43,8 +43,8 @@ impl Attachment {
/// Download all of the attachments associated with a [`Message`]:
///
/// ```rust,no_run
+ /// use serenity::model::prelude::*;
/// use serenity::prelude::*;
- /// use serenity::model::*;
/// use std::env;
/// use std::fs::File;
/// use std::io::Write;
@@ -52,7 +52,6 @@ impl Attachment {
///
/// struct Handler;
///
- ///
/// impl EventHandler for Handler {
/// fn message(&self, _: Context, message: Message) {
/// for attachment in message.attachments {
diff --git a/src/model/channel/channel_category.rs b/src/model/channel/channel_category.rs
index 73c50a7..f6df342 100644
--- a/src/model/channel/channel_category.rs
+++ b/src/model/channel/channel_category.rs
@@ -1,4 +1,4 @@
-use model::*;
+use model::prelude::*;
#[cfg(all(feature = "builder", feature = "model"))]
use builder::EditChannel;
diff --git a/src/model/channel/channel_id.rs b/src/model/channel/channel_id.rs
index acd3704..7ec6dfe 100644
--- a/src/model/channel/channel_id.rs
+++ b/src/model/channel/channel_id.rs
@@ -1,5 +1,5 @@
use internal::RwLockExt;
-use model::*;
+use model::prelude::*;
#[cfg(feature = "model")]
use std::borrow::Cow;
@@ -408,7 +408,7 @@ impl ChannelId {
/// Send files with the paths `/path/to/file.jpg` and `/path/to/file2.jpg`:
///
/// ```rust,no_run
- /// use serenity::model::ChannelId;
+ /// use serenity::model::id::ChannelId;
///
/// let channel_id = ChannelId(7);
///
@@ -420,7 +420,7 @@ impl ChannelId {
/// Send files using `File`:
///
/// ```rust,no_run
- /// use serenity::model::ChannelId;
+ /// use serenity::model::id::ChannelId;
/// use std::fs::File;
///
/// let channel_id = ChannelId(7);
diff --git a/src/model/channel/embed.rs b/src/model/channel/embed.rs
index a839beb..3cbe5ac 100644
--- a/src/model/channel/embed.rs
+++ b/src/model/channel/embed.rs
@@ -78,7 +78,7 @@ impl Embed {
/// Create an embed:
///
/// ```rust,no_run
- /// use serenity::model::Embed;
+ /// use serenity::model::channel::Embed;
///
/// let embed = Embed::fake(|e| e
/// .title("Embed title")
diff --git a/src/model/channel/group.rs b/src/model/channel/group.rs
index dfdfd0f..bff58aa 100644
--- a/src/model/channel/group.rs
+++ b/src/model/channel/group.rs
@@ -1,5 +1,5 @@
use chrono::{DateTime, FixedOffset};
-use model::*;
+use model::prelude::*;
#[cfg(feature = "model")]
use builder::{CreateMessage, GetMessages};
diff --git a/src/model/channel/guild_channel.rs b/src/model/channel/guild_channel.rs
index 54f802d..9b8371d 100644
--- a/src/model/channel/guild_channel.rs
+++ b/src/model/channel/guild_channel.rs
@@ -1,5 +1,5 @@
use chrono::{DateTime, FixedOffset};
-use model::*;
+use model::prelude::*;
#[cfg(all(feature = "cache", feature = "model"))]
use CACHE;
@@ -137,18 +137,17 @@ impl GuildChannel {
/// permissions:
///
/// ```rust,no_run
- /// # use serenity::model::{ChannelId, Permissions, UserId};
+ /// # use serenity::model::id::{ChannelId, UserId};
/// # use std::error::Error;
/// #
/// # fn try_main() -> Result<(), Box<Error>> {
/// # let (channel_id, user_id) = (ChannelId(0), UserId(0));
/// #
- /// use serenity::model::{
- /// ModelError,
+ /// use serenity::model::channel::{
/// PermissionOverwrite,
/// PermissionOverwriteType,
- /// permissions,
/// };
+ /// use serenity::model::{ModelError, Permissions};
/// use serenity::CACHE;
///
/// let allow = Permissions::SEND_MESSAGES;
@@ -179,18 +178,17 @@ impl GuildChannel {
/// permissions:
///
/// ```rust,no_run
- /// # use serenity::model::{ChannelId, Permissions, UserId};
+ /// # use serenity::model::id::{ChannelId, UserId};
/// # use std::error::Error;
/// #
/// # fn try_main() -> Result<(), Box<Error>> {
/// # let (channel_id, user_id) = (ChannelId(0), UserId(0));
/// #
- /// use serenity::model::{
- /// ModelError,
+ /// use serenity::model::channel::{
/// PermissionOverwrite,
/// PermissionOverwriteType,
- /// permissions,
/// };
+ /// use serenity::model::{ModelError, Permissions};
/// use serenity::CACHE;
///
/// let allow = Permissions::SEND_MESSAGES;
@@ -425,7 +423,7 @@ impl GuildChannel {
///
/// ```rust,no_run
/// use serenity::prelude::*;
- /// use serenity::model::*;
+ /// use serenity::model::prelude::*;
/// struct Handler;
///
/// use serenity::CACHE;
@@ -452,10 +450,9 @@ impl GuildChannel {
/// for demonstrative purposes):
///
/// ```rust,no_run
- /// use serenity::prelude::*;
- /// use serenity::model::*;
/// use serenity::CACHE;
- /// use serenity::model::permissions;
+ /// use serenity::prelude::*;
+ /// use serenity::model::prelude::*;
/// use std::fs::File;
///
/// struct Handler;
@@ -468,11 +465,10 @@ impl GuildChannel {
/// };
///
/// let current_user_id = CACHE.read().user.id;
- /// let permissions =
- /// channel.read().permissions_for(current_user_id).unwrap();
+ /// let permissions =
+ /// channel.read().permissions_for(current_user_id).unwrap();
///
- /// if !permissions.contains(Permissions::ATTACH_FILES |
- /// Permissions::SEND_MESSAGES) {
+ /// if !permissions.contains(Permissions::ATTACH_FILES | Permissions::SEND_MESSAGES) {
/// return;
/// }
///
@@ -485,8 +481,8 @@ impl GuildChannel {
/// },
/// };
///
- /// let _ = msg.channel_id.send_files(vec![(&file, "cat.png")], |m|
- /// m.content("here's a cat"));
+ /// let _ = msg.channel_id.send_files(vec![(&file, "cat.png")], |m|
+ /// m.content("here's a cat"));
/// }
/// }
///
diff --git a/src/model/channel/message.rs b/src/model/channel/message.rs
index 65df51a..f139aab 100644
--- a/src/model/channel/message.rs
+++ b/src/model/channel/message.rs
@@ -1,5 +1,7 @@
+//! Models relating to Discord channels.
+
use chrono::{DateTime, FixedOffset};
-use model::*;
+use model::prelude::*;
use serde_json::Value;
#[cfg(feature = "model")]
@@ -85,7 +87,7 @@ impl Message {
/// # impl EventHandler for Handler {}
/// # let mut client = Client::new("token", Handler).unwrap();
/// #
- /// use serenity::model::Channel;
+ /// use serenity::model::channel::Channel;
/// use serenity::framework::StandardFramework;
///
/// client.with_framework(StandardFramework::new()
diff --git a/src/model/channel/mod.rs b/src/model/channel/mod.rs
index 2fc4cbc..479818b 100644
--- a/src/model/channel/mod.rs
+++ b/src/model/channel/mod.rs
@@ -1,3 +1,5 @@
+//! Models relating to channels and types within channels.
+
mod attachment;
mod channel_id;
mod embed;
@@ -19,7 +21,7 @@ pub use self::reaction::*;
pub use self::channel_category::*;
use internal::RwLockExt;
-use model::*;
+use model::prelude::*;
use serde::de::Error as DeError;
use serde_json;
use super::utils::deserialize_u64;
diff --git a/src/model/channel/private_channel.rs b/src/model/channel/private_channel.rs
index a05b750..c9b6524 100644
--- a/src/model/channel/private_channel.rs
+++ b/src/model/channel/private_channel.rs
@@ -1,5 +1,5 @@
use chrono::{DateTime, FixedOffset};
-use model::*;
+use model::prelude::*;
use std::fmt::{Display, Formatter, Result as FmtResult};
use super::deserialize_single_recipient;
diff --git a/src/model/channel/reaction.rs b/src/model/channel/reaction.rs
index b2fdffd..5c1ee4d 100644
--- a/src/model/channel/reaction.rs
+++ b/src/model/channel/reaction.rs
@@ -1,4 +1,4 @@
-use model::*;
+use model::prelude::*;
use serde::de::{Deserialize, Error as DeError, MapAccess, Visitor};
use std::error::Error as StdError;
use std::fmt::{Display, Formatter, Result as FmtResult, Write as FmtWrite};
@@ -270,7 +270,7 @@ impl From<char> for ReactionType {
/// Reacting to a message with an apple:
///
/// ```rust,no_run
- /// # use serenity::model::ChannelId;
+ /// # use serenity::model::id::ChannelId;
/// # use std::error::Error;
/// #
/// # fn try_main() -> Result<(), Box<Error>> {
@@ -327,7 +327,7 @@ impl<'a> From<&'a str> for ReactionType {
/// rest of the library:
///
/// ```rust
- /// use serenity::model::ReactionType;
+ /// use serenity::model::channel::ReactionType;
///
/// fn foo<R: Into<ReactionType>>(bar: R) {
/// println!("{:?}", bar.into());