aboutsummaryrefslogtreecommitdiff
path: root/src/model/mod.rs
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2017-04-24 22:51:22 -0700
committerZeyla Hellyer <[email protected]>2017-04-24 22:51:22 -0700
commit6aeea4da70da26631533b27052133f3620cebc5a (patch)
treee82e21cf13f804f33216a69e25d42098291e3c94 /src/model/mod.rs
parentRemove example 01 debugging (diff)
downloadserenity-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.rs10
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)
+ }
+ }
)*
}
}