journallib/enums/
lesson_type.rsuse serde::Deserialize;
use serde::Serialize;
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,
diesel::{AsExpression, FromSqlRow},
};
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, AsExpression, FromSqlRow)]
#[sql_type = "Varchar"]
pub enum LessonType {
Test,
FinalTest,
CommonLesson,
TestOutsideTheSystem,
VideoConference,
}
impl ToSql<Varchar, Pg> for LessonType {
fn to_sql<W: Write>(&self, out: &mut Output<W, Pg>) -> serialize::Result {
match *self {
LessonType::Test => out.write_all(b"Test")?,
LessonType::FinalTest => out.write_all(b"FinalTest")?,
LessonType::CommonLesson => out.write_all(b"CommonLesson")?,
LessonType::TestOutsideTheSystem => out.write_all(b"TestOutsideTheSystem")?,
LessonType::VideoConference => out.write_all(b"VideoConference")?,
}
Ok(IsNull::No)
}
}
impl FromSql<Varchar, Pg> for LessonType {
fn from_sql(bytes: Option<&<Pg as Backend>::RawValue>) -> deserialize::Result<Self> {
match not_none!(bytes) {
b"Test" => Ok(LessonType::Test),
b"FinalTest" => Ok(LessonType::FinalTest),
b"CommonLesson" => Ok(LessonType::CommonLesson),
b"TestOutsideTheSystem" => Ok(LessonType::TestOutsideTheSystem),
b"VideoConference" => Ok(LessonType::VideoConference),
_ => Err("Unrecognized enum variant".into()),
}
}
}