wellbeinglib/enums/
details_type.rsuse std::fmt;
use std::fmt::Formatter;
use std::str;
use serde::Deserialize;
use serde::Serialize;
#[cfg(feature = "diesel")]
use {
diesel::{deserialize, not_none, serialize},
diesel::{AsExpression, FromSqlRow},
diesel::backend::Backend,
diesel::deserialize::FromSql,
diesel::pg::Pg,
diesel::serialize::{IsNull, Output, ToSql},
diesel::types::Varchar,
std::io::Write,
};
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[cfg_attr(
feature = "diesel",
derive(AsExpression, FromSqlRow),
sql_type = "Varchar"
)]
pub enum DetailsType {
Create,
Update,
Extension,
Lapse,
Void,
Other,
None,
}
impl fmt::Display for DetailsType {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}
}
impl Default for DetailsType {
fn default() -> Self {
DetailsType::None
}
}
#[cfg(feature = "diesel")]
impl ToSql<Varchar, Pg> for DetailsType {
fn to_sql<W: Write>(&self, out: &mut Output<W, Pg>) -> serialize::Result {
match *self {
DetailsType::Create => out.write_all(b"Create")?,
DetailsType::Update => out.write_all(b"Update")?,
DetailsType::Extension => out.write_all(b"Extension")?,
DetailsType::Lapse => out.write_all(b"Lapse")?,
DetailsType::Void => out.write_all(b"Void")?,
DetailsType::Other => out.write_all(b"Other")?,
DetailsType::None => out.write_all(b"None")?,
}
Ok(IsNull::No)
}
}
#[cfg(feature = "diesel")]
impl FromSql<Varchar, Pg> for DetailsType {
fn from_sql(bytes: Option<&<Pg as Backend>::RawValue>) -> deserialize::Result<Self> {
match not_none!(bytes) {
b"Create" => Ok(DetailsType::Create),
b"Update" => Ok(DetailsType::Update),
b"Extension" => Ok(DetailsType::Extension),
b"Lapse" => Ok(DetailsType::Lapse),
b"Void" => Ok(DetailsType::Void),
b"Other" => Ok(DetailsType::Other),
b"None" => Ok(DetailsType::None),
_ => Err("Unrecognized enum variant".into()),
}
}
}