chore: init repo
This commit is contained in:
commit
cc2f02dfe6
6 changed files with 136 additions and 0 deletions
55
src/defs.rs
Normal file
55
src/defs.rs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
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"),
|
||||
}
|
||||
}
|
||||
}
|
||||
1
src/lib.rs
Normal file
1
src/lib.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
pub mod defs;
|
||||
Loading…
Add table
Add a link
Reference in a new issue