|
|
|
@ -21,8 +21,10 @@ pub struct Notification { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// The type of notification.
|
|
|
|
|
#[derive(Debug, Clone, Copy, Deserialize, PartialEq)] |
|
|
|
|
#[derive(Debug, Clone, Deserialize, PartialEq)] |
|
|
|
|
#[serde(rename_all = "lowercase")] |
|
|
|
|
// Deserialize "Other" trick from https://github.com/serde-rs/serde/issues/912#issuecomment-803097289
|
|
|
|
|
#[serde(remote = "NotificationType")] |
|
|
|
|
pub enum NotificationType { |
|
|
|
|
/// Someone mentioned the application client in another status.
|
|
|
|
|
Mention, |
|
|
|
@ -32,4 +34,30 @@ pub enum NotificationType { |
|
|
|
|
Favourite, |
|
|
|
|
/// Someone followed the application client.
|
|
|
|
|
Follow, |
|
|
|
|
/// Anything else
|
|
|
|
|
#[serde(skip_deserializing)] |
|
|
|
|
Other(String), |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
use std::str::FromStr; |
|
|
|
|
use serde::de::{value, Deserializer, IntoDeserializer}; |
|
|
|
|
|
|
|
|
|
impl FromStr for NotificationType { |
|
|
|
|
type Err = value::Error; |
|
|
|
|
|
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> { |
|
|
|
|
Self::deserialize(s.into_deserializer()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl<'de> Deserialize<'de> for NotificationType { |
|
|
|
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> |
|
|
|
|
where D: Deserializer<'de> |
|
|
|
|
{ |
|
|
|
|
let s = String::deserialize(deserializer)?; |
|
|
|
|
let deserialized = Self::from_str(&s).unwrap_or_else(|_| { |
|
|
|
|
Self::Other(s) |
|
|
|
|
}); |
|
|
|
|
Ok(deserialized) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|