use sqlx::error::BoxDynError; use sqlx::{Database, Decode, Encode, Postgres, Type}; use sqlx::encode::IsNull; #[repr(i32)] #[derive(Clone, Copy)] pub enum DefaultMessageNotificationSetting { All = 0, MentionsOnly = 1, None = 2, } impl Into for &DefaultMessageNotificationSetting { fn into(self) -> i32 { *self as i32 } } impl TryFrom for DefaultMessageNotificationSetting { type Error = BoxDynError; fn try_from(value: i32) -> Result { match value { 0 => Ok(Self::All), 1 => Ok(Self::MentionsOnly), 2 => Ok(Self::None), _ => Err(format!("Unknown value {}", value).into()), } } } impl Type for DefaultMessageNotificationSetting { fn type_info() -> ::TypeInfo { >::type_info() } fn compatible(ty: &::TypeInfo) -> bool { >::compatible(ty) } } impl Encode<'_, Postgres> for DefaultMessageNotificationSetting { fn encode_by_ref(&self, buf: &mut ::ArgumentBuffer<'_>) -> Result { >::encode(self.into(), buf) } } impl Decode<'_, Postgres> for DefaultMessageNotificationSetting { fn decode(value: ::ValueRef<'_>) -> Result { >::decode(value).map(Self::try_from)? } }