diff options
| author | Zeyla Hellyer <[email protected]> | 2017-12-16 08:39:36 -0800 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-12-16 08:45:26 -0800 |
| commit | bcd16dddb8cc3086a13524c79676f3a8bebbc524 (patch) | |
| tree | 42d254fb4738df957c4b7d9e5766d1cb5bd47323 /src/model/utils.rs | |
| parent | Fix guild deserialization tests (diff) | |
| download | serenity-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/utils.rs')
| -rw-r--r-- | src/model/utils.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/model/utils.rs b/src/model/utils.rs index 52e3bbc..9d4ca88 100644 --- a/src/model/utils.rs +++ b/src/model/utils.rs @@ -2,7 +2,7 @@ use parking_lot::RwLock; use serde::de::Error as DeError; use std::collections::HashMap; use std::sync::Arc; -use super::*; +use super::prelude::*; #[cfg(feature = "cache")] use internal::prelude::*; @@ -12,6 +12,10 @@ use super::permissions::Permissions; #[cfg(all(feature = "cache", feature = "model"))] use CACHE; +pub fn default_true() -> bool { + true +} + pub fn deserialize_emojis<'de, D: Deserializer<'de>>( deserializer: D) -> StdResult<HashMap<EmojiId, Emoji>, D::Error> { @@ -112,6 +116,11 @@ pub fn deserialize_single_recipient<'de, D: Deserializer<'de>>( Ok(Arc::new(RwLock::new(user))) } +pub fn deserialize_sync_user<'de, D>(deserializer: D) + -> StdResult<Arc<RwLock<User>>, D::Error> where D: Deserializer<'de> { + Ok(Arc::new(RwLock::new(User::deserialize(deserializer)?))) +} + pub fn deserialize_users<'de, D: Deserializer<'de>>( deserializer: D) -> StdResult<HashMap<UserId, Arc<RwLock<User>>>, D::Error> { |