Split up types
This commit is contained in:
parent
127ccfb26b
commit
293053134f
5 changed files with 151 additions and 135 deletions
50
src/types/account.rs
Normal file
50
src/types/account.rs
Normal file
|
@ -0,0 +1,50 @@
|
|||
#[cfg(feature = "server")]
|
||||
use rusqlite::{types::ToSqlOutput, ToSql};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
|
||||
pub enum Account {
|
||||
Sumpf,
|
||||
Heinersyndikat,
|
||||
}
|
||||
|
||||
impl TryFrom<&str> for Account {
|
||||
type Error = ();
|
||||
|
||||
fn try_from(s: &str) -> Result<Self, Self::Error> {
|
||||
match s {
|
||||
"sumpf" => Ok(Account::Sumpf),
|
||||
"hs" => Ok(Account::Heinersyndikat),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<String> for &Account {
|
||||
fn into(self) -> String {
|
||||
String::from(match *self {
|
||||
Account::Sumpf => "sumpf",
|
||||
Account::Heinersyndikat => "hs",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Account {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match *self {
|
||||
Account::Sumpf => "Sumpf",
|
||||
Account::Heinersyndikat => "Heinersyndikat",
|
||||
}
|
||||
.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
impl ToSql for Account {
|
||||
fn to_sql(&self) -> rusqlite::Result<ToSqlOutput<'_>> {
|
||||
match self {
|
||||
Account::Sumpf => 0.to_sql(),
|
||||
Account::Heinersyndikat => 1.to_sql(),
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue