35 lines
1.1 KiB
Rust
35 lines
1.1 KiB
Rust
use serde::{ser::SerializeStruct, Serialize, Serializer};
|
|
|
|
use super::{User, Username};
|
|
|
|
pub fn deserialize_id<'de, D>(deserializer: D) -> Result<u64, D::Error>
|
|
where
|
|
D: serde::Deserializer<'de>,
|
|
{
|
|
let id_str: &str = serde::Deserialize::deserialize(deserializer)?;
|
|
id_str.parse().map_err(serde::de::Error::custom)
|
|
}
|
|
|
|
pub fn deserialize_discriminator<'de, D>(deserializer: D) -> Result<u16, D::Error>
|
|
where
|
|
D: serde::Deserializer<'de>,
|
|
{
|
|
let id_str: &str = serde::Deserialize::deserialize(deserializer)?;
|
|
id_str.parse().map_err(serde::de::Error::custom)
|
|
}
|
|
|
|
impl Serialize for User {
|
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
where
|
|
S: Serializer,
|
|
{
|
|
let mut state = serializer.serialize_struct("User", 6)?;
|
|
state.serialize_field("id", &self.id)?;
|
|
state.serialize_field("name", &self.name)?;
|
|
state.serialize_field("discriminator", &self.discriminator)?;
|
|
state.serialize_field("avatar", &self.avatar())?;
|
|
state.serialize_field("deleted", &self.deleted)?;
|
|
state.serialize_field("username", &self.username())?;
|
|
state.end()
|
|
}
|
|
}
|