Skip to content

Commit d914044

Browse files
committed
refactor: remove Cfs prefix from store types
1 parent 648f4a7 commit d914044

4 files changed

Lines changed: 40 additions & 39 deletions

File tree

src/actions.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use seahorse::{ActionError, ActionResult, Context};
44

55
use crate::config::get_config_path;
66
use crate::error::invalid;
7-
use crate::storage::json::CfsJSONStore;
8-
use crate::storage::{CfsStorage, CfsValue};
7+
use crate::storage::json::JSONStore;
8+
use crate::storage::{Store, StoreValue};
99

1010
pub fn init_action(_c: &Context) -> ActionResult {
1111
let config_path = get_config_path();
@@ -15,13 +15,13 @@ pub fn init_action(_c: &Context) -> ActionResult {
1515
println!("config file already exists");
1616
}
1717

18-
CfsJSONStore::with_force_create(true);
18+
JSONStore::with_force_create(true);
1919

2020
Ok(())
2121
}
2222

2323
pub fn list_action(c: &Context) -> ActionResult {
24-
let store = CfsJSONStore::with_force_create(c.bool_flag("force-create"));
24+
let store = JSONStore::with_force_create(c.bool_flag("force-create"));
2525

2626
for (key, value) in store.all().iter() {
2727
println!("{}\t{}", key, value);
@@ -31,7 +31,7 @@ pub fn list_action(c: &Context) -> ActionResult {
3131
}
3232

3333
pub fn clear_action(_c: &Context) -> ActionResult {
34-
let mut store = CfsJSONStore::new();
34+
let mut store = JSONStore::new();
3535

3636
store.clear();
3737

@@ -51,7 +51,7 @@ pub fn get_action(c: &Context) -> ActionResult {
5151
return Err(invalid("key"));
5252
};
5353

54-
let store = CfsJSONStore::new();
54+
let store = JSONStore::new();
5555

5656
let value = store.get(key);
5757

@@ -86,9 +86,9 @@ pub fn set_action(c: &Context) -> ActionResult {
8686
return Err(invalid("value"));
8787
};
8888

89-
let mut store = CfsJSONStore::new();
89+
let mut store = JSONStore::new();
9090

91-
let value = CfsValue::Value(value_str.to_owned());
91+
let value = StoreValue::Value(value_str.to_owned());
9292
store.set(key, value.clone());
9393

9494
println!("{}\t{}", key, value);
@@ -101,7 +101,7 @@ pub fn remove_action(c: &Context) -> ActionResult {
101101
return Err(invalid("key"));
102102
};
103103

104-
let mut store = CfsJSONStore::new();
104+
let mut store = JSONStore::new();
105105

106106
match store.remove(key) {
107107
Some(value) => println!("{}\t{}", key, value),

src/storage/json.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::process::exit;
66
use json::JsonValue;
77

88
use crate::config::get_config_path;
9-
use crate::storage::{CfsStorage, CfsValue};
9+
use crate::storage::{Store, StoreValue};
1010

1111
pub fn init_store(force_create: bool) -> JsonValue {
1212
let path = get_config_path();
@@ -30,11 +30,11 @@ pub fn init_store(force_create: bool) -> JsonValue {
3030
}
3131

3232
#[derive(Clone, Debug)]
33-
pub struct CfsJSONStore {
33+
pub struct JSONStore {
3434
store: JsonValue,
3535
}
3636

37-
impl CfsJSONStore {
37+
impl JSONStore {
3838
pub fn new() -> Self {
3939
return Self {
4040
store: init_store(false),
@@ -58,32 +58,32 @@ impl CfsJSONStore {
5858
}
5959
}
6060

61-
impl CfsStorage for CfsJSONStore {
62-
fn all(&self) -> Vec<(String, CfsValue)> {
61+
impl Store for JSONStore {
62+
fn all(&self) -> Vec<(String, StoreValue)> {
6363
self
6464
.store
6565
.entries()
6666
.map(|(key, value)| (key.to_owned(), value.into()))
6767
.collect()
6868
}
6969

70-
fn get(&self, key: &str) -> Option<CfsValue> {
70+
fn get(&self, key: &str) -> Option<StoreValue> {
7171
if !self.store.has_key(key) {
7272
return None;
7373
}
7474

7575
Some(self.store[key].clone().into())
7676
}
7777

78-
fn set(&mut self, key: &str, value: CfsValue) -> CfsValue {
78+
fn set(&mut self, key: &str, value: StoreValue) -> StoreValue {
7979
self.store.insert(key, value.clone()).unwrap();
8080

8181
self.save_store().unwrap();
8282

8383
value
8484
}
8585

86-
fn remove(&mut self, key: &str) -> Option<CfsValue> {
86+
fn remove(&mut self, key: &str) -> Option<StoreValue> {
8787
if !self.store.has_key(key) {
8888
return None;
8989
}

src/storage/mod.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
pub mod json;
2+
mod sqlite;
23
mod value;
34

4-
pub use value::CfsValue;
5+
pub use value::StoreValue;
56

6-
pub trait CfsStorage {
7-
fn all(&self) -> Vec<(String, CfsValue)>;
7+
pub trait Store {
8+
fn all(&self) -> Vec<(String, StoreValue)>;
89

9-
fn get(&self, key: &str) -> Option<CfsValue>;
10-
fn set(&mut self, key: &str, value: CfsValue) -> CfsValue;
11-
fn remove(&mut self, key: &str) -> Option<CfsValue>;
10+
fn get(&self, key: &str) -> Option<StoreValue>;
11+
fn set(&mut self, key: &str, value: StoreValue) -> StoreValue;
12+
fn remove(&mut self, key: &str) -> Option<StoreValue>;
1213

1314
fn clear(&mut self);
1415
}

src/storage/value.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ use std::fmt::Display;
33
use json::JsonValue;
44

55
#[derive(Debug, Clone)]
6-
pub enum CfsValue {
6+
pub enum StoreValue {
77
Value(String),
88
List(Vec<String>),
99
}
1010

11-
impl Display for CfsValue {
11+
impl Display for StoreValue {
1212
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1313
match self {
14-
CfsValue::Value(v) => write!(f, "{}", v),
15-
CfsValue::List(items) => {
14+
StoreValue::Value(v) => write!(f, "{}", v),
15+
StoreValue::List(items) => {
1616
let mut array_string = String::new();
1717
for i in items.iter() {
1818
array_string.push_str(&format!("{},", i));
@@ -24,37 +24,37 @@ impl Display for CfsValue {
2424
}
2525
}
2626

27-
impl From<CfsValue> for JsonValue {
28-
fn from(value: CfsValue) -> Self {
27+
impl From<StoreValue> for JsonValue {
28+
fn from(value: StoreValue) -> Self {
2929
match value {
30-
CfsValue::Value(string) => JsonValue::String(string),
31-
CfsValue::List(items) => {
30+
StoreValue::Value(string) => JsonValue::String(string),
31+
StoreValue::List(items) => {
3232
JsonValue::Array(items.into_iter().map(|i| JsonValue::String(i)).collect())
3333
}
3434
}
3535
}
3636
}
3737

38-
impl From<JsonValue> for CfsValue {
38+
impl From<JsonValue> for StoreValue {
3939
fn from(value: JsonValue) -> Self {
4040
match value {
4141
JsonValue::Array(json_values) => {
42-
CfsValue::List(json_values.iter().map(|f| f.to_string()).collect())
42+
StoreValue::List(json_values.iter().map(|f| f.to_string()).collect())
4343
}
44-
JsonValue::String(string) => CfsValue::Value(string),
45-
_ => CfsValue::Value(value.to_string()),
44+
JsonValue::String(string) => StoreValue::Value(string),
45+
_ => StoreValue::Value(value.to_string()),
4646
}
4747
}
4848
}
4949

50-
impl From<&JsonValue> for CfsValue {
50+
impl From<&JsonValue> for StoreValue {
5151
fn from(value: &JsonValue) -> Self {
5252
match value {
5353
JsonValue::Array(json_values) => {
54-
CfsValue::List(json_values.iter().map(|f| f.to_string()).collect())
54+
StoreValue::List(json_values.iter().map(|f| f.to_string()).collect())
5555
}
56-
JsonValue::String(string) => CfsValue::Value(string.clone()),
57-
_ => CfsValue::Value(value.to_string()),
56+
JsonValue::String(string) => StoreValue::Value(string.clone()),
57+
_ => StoreValue::Value(value.to_string()),
5858
}
5959
}
6060
}

0 commit comments

Comments
 (0)