settingslib/enums/
communication_type.rsuse serde::Deserialize;
use serde::Serialize;
#[cfg(feature = "diesel")]
use {
diesel::backend::Backend,
diesel::deserialize::FromSql,
diesel::pg::Pg,
diesel::serialize::{IsNull, Output, ToSql},
diesel::sql_types::Varchar,
diesel::{deserialize, not_none, serialize},
std::io::Write,
};
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
feature = "diesel",
derive(AsExpression, FromSqlRow),
sql_type = "Varchar"
)]
pub enum CommunicationType {
Email,
Forms,
OnSite,
}
#[cfg(feature = "diesel")]
impl ToSql<Varchar, Pg> for CommunicationType {
fn to_sql<W: Write>(&self, out: &mut Output<W, Pg>) -> serialize::Result {
match *self {
CommunicationType::Email => out.write_all(b"Email")?,
CommunicationType::Forms => out.write_all(b"Forms")?,
CommunicationType::OnSite => out.write_all(b"OnSite")?,
}
Ok(IsNull::No)
}
}
#[cfg(feature = "diesel")]
impl FromSql<Varchar, Pg> for CommunicationType {
fn from_sql(bytes: Option<&<Pg as Backend>::RawValue>) -> deserialize::Result<Self> {
match not_none!(bytes) {
b"Email" => Ok(CommunicationType::Email),
b"Forms" => Ok(CommunicationType::Forms),
b"OnSite" => Ok(CommunicationType::OnSite),
_ => Err("Unrecognized enum variant".into()),
}
}
}
impl Default for CommunicationType {
fn default() -> CommunicationType {
CommunicationType::OnSite
}
}