initiativelib/enums/
participant_type.rsuse serde::Deserialize;
use serde::Serialize;
use std::str;
use strum_macros::EnumString;
#[cfg(feature = "diesel")]
use {
diesel::backend::Backend,
diesel::deserialize::FromSql,
diesel::pg::Pg,
diesel::serialize::{IsNull, Output, ToSql},
diesel::types::Varchar,
diesel::{deserialize, not_none, serialize},
diesel::{AsExpression, FromSqlRow},
std::io::Write,
};
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, EnumString)]
#[cfg_attr(feature = "diesel", derive(AsExpression, FromSqlRow))]
#[cfg_attr(feature = "diesel", sql_type = "Varchar")]
pub enum ParticipantType {
Staff,
Student,
Person,
School,
Organization,
Other,
}
#[cfg(feature = "diesel")]
impl ToSql<Varchar, Pg> for ParticipantType {
fn to_sql<W: Write>(&self, out: &mut Output<W, Pg>) -> serialize::Result {
match *self {
ParticipantType::Staff => out.write_all(b"Staff")?,
ParticipantType::Student => out.write_all(b"Student")?,
ParticipantType::Person => out.write_all(b"Person")?,
ParticipantType::School => out.write_all(b"School")?,
ParticipantType::Organization => out.write_all(b"Organization")?,
ParticipantType::Other => out.write_all(b"Other")?,
}
Ok(IsNull::No)
}
}
#[cfg(feature = "diesel")]
impl FromSql<Varchar, Pg> for ParticipantType {
fn from_sql(bytes: Option<&<Pg as Backend>::RawValue>) -> deserialize::Result<Self> {
match not_none!(bytes) {
b"Staff" => Ok(ParticipantType::Staff),
b"Student" => Ok(ParticipantType::Student),
b"Person" => Ok(ParticipantType::Person),
b"School" => Ok(ParticipantType::School),
b"Organization" => Ok(ParticipantType::Organization),
b"Other" => Ok(ParticipantType::Other),
_ => Err("Unrecognized enum variant".into()),
}
}
}