lib_datastores_defs/src/defs.rs
2021-09-20 13:03:55 +01:00

56 lines
1.5 KiB
Rust

use serde::{Serialize,Deserialize};
use std::fmt;
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
/// `DataStore` options
pub enum DataStore {
File,
Mysql, // (sqlx::MySqlPool),
Postgres, // (sqlx::PgPool),
Sqlite, // (sqlx::SqlitePool),
Redis, // (redis::Client),
// Tikv, // (tikv::RawClient),
Slab, // (Storage),
Unknown,
}
pub type OptionDataStore = Option<DataStore>;
impl Default for DataStore {
fn default() -> Self {
DataStore::Unknown
}
}
impl DataStore {
/// Get `DataStore`from String to enum
#[must_use]
pub fn get_from(str: String) -> DataStore {
match str.as_str() {
"file" | "File" => DataStore::File,
"mysql" | "Mysql" | "MySql" => DataStore::Mysql,
"postgres" | "Postgres" | "pg" => DataStore::Postgres,
"sqlite" | "Sqlite" => DataStore::Sqlite,
"redis" | "Redis" => DataStore::Redis,
// "tikv" | "Tikv" => DataStore::Tikv,
"slab" | "Slab" => DataStore::Slab,
_ => DataStore::Unknown,
}
}
}
#[allow(clippy::pattern_type_mismatch)]
impl fmt::Display for DataStore {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
DataStore::File => write!(f, "file"),
DataStore::Mysql => write!(f, "mysql"),
DataStore::Postgres => write!(f, "postgres"),
DataStore::Sqlite => write!(f, "sqlite"),
DataStore::Redis => write!(f, "redis"),
// DataStore::Tikv => write!(f, "tikv"),
DataStore::Slab => write!(f, "slab"),
DataStore::Unknown => write!(f, "Unknown"),
}
}
}