Skip to content

Commit

Permalink
Merge pull request #108 from suchapalaver/fix/store-methods-improvements
Browse files Browse the repository at this point in the history
fix: fix unneccessary '&mut' to 'self' in methods
  • Loading branch information
suchapalaver authored Dec 31, 2023
2 parents 7192d55 + 4c8a550 commit 4790152
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 94 deletions.
4 changes: 1 addition & 3 deletions crates/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ impl Api {
let dispatch = ApiDispatch { tx };

tokio::task::spawn(async move {
let mut api = api;

loop {
tokio::select! {
cmd = rx.recv().fuse() => {
Expand All @@ -76,7 +74,7 @@ impl Api {
}

#[instrument(level = "debug", skip(self), ret(Debug))]
async fn execute(&mut self, command: ApiCommand) -> Result<ApiResponse, ApiError> {
async fn execute(&self, command: ApiCommand) -> Result<ApiResponse, ApiError> {
let (tx, rx) = oneshot::channel();
self.store.send((command, tx)).await?;
let res = rx.await??;
Expand Down
36 changes: 18 additions & 18 deletions crates/persistence/src/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl JsonStore {
}

impl Storage for JsonStore {
async fn add_item(&mut self, item: &Name) -> Result<StoreResponse, StoreError> {
async fn add_item(&self, item: &Name) -> Result<StoreResponse, StoreError> {
let mut groceries = Items::from_json(&self.items)?;

if groceries
Expand All @@ -82,51 +82,51 @@ impl Storage for JsonStore {
}
}

async fn add_checklist_item(&mut self, _item: &Name) -> Result<StoreResponse, StoreError> {
async fn add_checklist_item(&self, _item: &Name) -> Result<StoreResponse, StoreError> {
todo!()
}

async fn add_list_item(&mut self, _item: &Name) -> Result<StoreResponse, StoreError> {
async fn add_list_item(&self, _item: &Name) -> Result<StoreResponse, StoreError> {
todo!()
}

async fn add_list_recipe(&mut self, _recipe: &Recipe) -> Result<StoreResponse, StoreError> {
async fn add_list_recipe(&self, _recipe: &Recipe) -> Result<StoreResponse, StoreError> {
todo!()
}

async fn add_recipe(
&mut self,
&self,
_recipe: &Recipe,
_ingredients: &Ingredients,
) -> Result<StoreResponse, StoreError> {
todo!()
}

async fn checklist(&mut self) -> Result<StoreResponse, StoreError> {
async fn checklist(&self) -> Result<StoreResponse, StoreError> {
todo!()
}

async fn delete_checklist_item(&mut self, _item: &Name) -> Result<StoreResponse, StoreError> {
async fn delete_checklist_item(&self, _item: &Name) -> Result<StoreResponse, StoreError> {
todo!()
}

async fn delete_recipe(&mut self, _recipe: &Recipe) -> Result<StoreResponse, StoreError> {
async fn delete_recipe(&self, _recipe: &Recipe) -> Result<StoreResponse, StoreError> {
todo!()
}

async fn items(&mut self) -> Result<StoreResponse, StoreError> {
async fn items(&self) -> Result<StoreResponse, StoreError> {
Ok(StoreResponse::Items(Items::from_json(&self.items)?))
}

async fn list(&mut self) -> Result<StoreResponse, StoreError> {
async fn list(&self) -> Result<StoreResponse, StoreError> {
Ok(StoreResponse::List(List::from_json(&self.list)?))
}

async fn refresh_list(&mut self) -> Result<StoreResponse, StoreError> {
async fn refresh_list(&self) -> Result<StoreResponse, StoreError> {
todo!()
}

async fn recipe_ingredients(&mut self, recipe: &Recipe) -> Result<StoreResponse, StoreError> {
async fn recipe_ingredients(&self, recipe: &Recipe) -> Result<StoreResponse, StoreError> {
let items = Items::from_json(&self.items)?;
let ingredients: Ingredients = items
.recipe_ingredients(&recipe.to_string())?
Expand All @@ -136,11 +136,11 @@ impl Storage for JsonStore {
Ok(StoreResponse::RecipeIngredients(Some(ingredients)))
}

async fn sections(&mut self) -> Result<StoreResponse, StoreError> {
async fn sections(&self) -> Result<StoreResponse, StoreError> {
todo!()
}

async fn recipes(&mut self) -> Result<StoreResponse, StoreError> {
async fn recipes(&self) -> Result<StoreResponse, StoreError> {
let mut recipes: HashSet<Recipe> = HashSet::new();

{
Expand Down Expand Up @@ -312,7 +312,7 @@ pub mod test {

async fn items() -> Items {
let file = test_json_file().unwrap();
let mut store = JsonStore::new().with_items_path(file.path());
let store = JsonStore::new().with_items_path(file.path());
let StoreResponse::Items(items) = store.items().await.unwrap() else {
todo!()
};
Expand All @@ -334,7 +334,7 @@ pub mod test {

#[tokio::test]
async fn test_save_items() -> Result<(), Box<dyn std::error::Error>> {
let mut store = JsonStore::new().with_items_path(&PathBuf::from("test_groceries.json"));
let store = JsonStore::new().with_items_path(&PathBuf::from("test_groceries.json"));
let items = Items::default();
insta::assert_json_snapshot!(items, @r#"
{
Expand Down Expand Up @@ -888,7 +888,7 @@ pub mod test {
#[tokio::test]
async fn test_delete_item_from_list() -> Result<(), Box<dyn std::error::Error>> {
let file = create_test_checklist_json_file().unwrap();
let mut store = JsonStore::new().with_list_path(file.path());
let store = JsonStore::new().with_list_path(file.path());

let StoreResponse::List(mut shopping_list) = store.list().await.unwrap() else {
todo!()
Expand Down Expand Up @@ -1119,7 +1119,7 @@ pub mod test {

async fn checklist() -> List {
let file = create_test_checklist_json_file().unwrap();
let mut store = JsonStore::new().with_list_path(file.path());
let store = JsonStore::new().with_list_path(file.path());
let StoreResponse::List(list) = store.list().await.unwrap() else {
todo!()
};
Expand Down
Loading

0 comments on commit 4790152

Please sign in to comment.