inventorylib/enums/
room_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 RoomType {
Educational ,
Medical,
Stuff,
Admenistrative,
Technical,
Comman,
Undefined,
}
impl fmt::Display for RoomType {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}
}
impl Default for RoomType {
fn default() -> Self {
RoomType::Undefined
}
}
#[cfg(feature = "diesel")]
impl ToSql<Varchar, Pg> for RoomType {
fn to_sql<W: Write>(&self, out: &mut Output<W, Pg>) -> serialize::Result {
match *self {
RoomType::Educational => out.write_all(b"Educational")?,
RoomType::Medical => out.write_all(b"Medical")?,
RoomType::Stuff => out.write_all(b"Stuff")?,
RoomType::Admenistrative => out.write_all(b"Admenistrative")?,
RoomType::Technical => out.write_all(b"Technical")?,
RoomType::Comman => out.write_all(b"Comman")?,
RoomType::Undefined => out.write_all(b"Undefined")?,
}
Ok(IsNull::No)
}
}
#[cfg(feature = "diesel")]
impl FromSql<Varchar, Pg> for RoomType {
fn from_sql(bytes: Option<&<Pg as Backend>::RawValue>) -> deserialize::Result<Self> {
match not_none!(bytes) {
b"Educational" => Ok(RoomType::Educational),
b"Medical" => Ok(RoomType::Medical),
b"Stuff" => Ok(RoomType::Stuff),
b"Admenistrative" => Ok(RoomType::Admenistrative),
b"Technical" => Ok(RoomType::Technical),
b"Comman" => Ok(RoomType::Comman),
b"Undefined" => Ok(RoomType::Undefined),
_ => Err("Unrecognized enum variant".into()),
}
}
}