diff options
| author | Zeyla Hellyer <[email protected]> | 2017-04-24 22:51:22 -0700 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-04-24 22:51:22 -0700 |
| commit | 6aeea4da70da26631533b27052133f3620cebc5a (patch) | |
| tree | e82e21cf13f804f33216a69e25d42098291e3c94 /src/model/mod.rs | |
| parent | Remove example 01 debugging (diff) | |
| download | serenity-6aeea4da70da26631533b27052133f3620cebc5a.tar.xz serenity-6aeea4da70da26631533b27052133f3620cebc5a.zip | |
Fix deserialization for Ids
Attempt to deserialize from both a str and a u64 instead of the default
derive impl.
Diffstat (limited to 'src/model/mod.rs')
| -rw-r--r-- | src/model/mod.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/model/mod.rs b/src/model/mod.rs index f464242..e51970d 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -39,7 +39,9 @@ pub use self::voice::*; pub use self::webhook::*; use self::utils::*; +use serde::de::Visitor; use std::collections::HashMap; +use std::fmt::{Formatter, Result as FmtResult}; use std::sync::{Arc, RwLock}; use time::Timespec; use ::internal::prelude::*; @@ -51,7 +53,7 @@ macro_rules! id { ($(#[$attr:meta] $name:ident;)*) => { $( #[$attr] - #[derive(Copy, Clone, Debug, Deserialize, Eq, Hash, PartialOrd, Ord, Serialize)] + #[derive(Copy, Clone, Debug, Eq, Hash, PartialOrd, Ord, Serialize)] #[allow(derive_hash_xor_eq)] pub struct $name(pub u64); @@ -81,6 +83,12 @@ macro_rules! id { self.0 == *u } } + + impl<'de> Deserialize<'de> for $name { + fn deserialize<D: Deserializer<'de>>(deserializer: D) -> StdResult<Self, D::Error> { + deserializer.deserialize_u64(U64Visitor).map($name) + } + } )* } } |