From 735e23be834d4829e98dcf4829f8cbe2217109b2 Mon Sep 17 00:00:00 2001 From: Nikita Galaiko Date: Tue, 7 Nov 2023 12:42:38 +0100 Subject: [PATCH] chore: refactor code to remove unnecessary references in function signatures --- packages/tauri/src/app.rs | 2 +- packages/tauri/src/commands.rs | 2 +- packages/tauri/src/deltas/reader.rs | 2 +- packages/tauri/src/gb_repository/repository_tests.rs | 12 ++++++------ packages/tauri/src/sessions/reader.rs | 2 +- packages/tauri/src/watcher/handlers/index_handler.rs | 2 +- .../src/watcher/handlers/project_file_change.rs | 12 ++++++------ 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/tauri/src/app.rs b/packages/tauri/src/app.rs index 8bb45a92e..a321747ac 100644 --- a/packages/tauri/src/app.rs +++ b/packages/tauri/src/app.rs @@ -129,7 +129,7 @@ impl App { &self, project_id: &ProjectId, session_id: &SessionId, - paths: &Option>, + paths: Option<&[path::PathBuf]>, ) -> Result, Error> { let session = self .sessions_database diff --git a/packages/tauri/src/commands.rs b/packages/tauri/src/commands.rs index 1eb9dc022..d1e5a1921 100644 --- a/packages/tauri/src/commands.rs +++ b/packages/tauri/src/commands.rs @@ -59,7 +59,7 @@ pub async fn list_session_files( code: Code::Validation, message: "Malformed project id".to_string(), })?; - let files = app.list_session_files(&project_id, &session_id, &paths)?; + let files = app.list_session_files(&project_id, &session_id, paths.as_deref())?; Ok(files) } diff --git a/packages/tauri/src/deltas/reader.rs b/packages/tauri/src/deltas/reader.rs index f270f4e03..e473dfc53 100644 --- a/packages/tauri/src/deltas/reader.rs +++ b/packages/tauri/src/deltas/reader.rs @@ -38,7 +38,7 @@ impl<'reader> DeltasReader<'reader> { pub fn read( &self, - paths: &Option>, + paths: Option<&[&path::Path]>, ) -> Result>> { let deltas_dir = path::Path::new("session/deltas"); let files = self.reader.list_files(deltas_dir)?; diff --git a/packages/tauri/src/gb_repository/repository_tests.rs b/packages/tauri/src/gb_repository/repository_tests.rs index 5720d5766..302d0f3a3 100644 --- a/packages/tauri/src/gb_repository/repository_tests.rs +++ b/packages/tauri/src/gb_repository/repository_tests.rs @@ -107,7 +107,7 @@ fn test_list_deltas_from_current_session() -> Result<()> { let session_reader = sessions::Reader::open(&gb_repository, ¤t_session)?; let deltas_reader = deltas::Reader::new(&session_reader); - let deltas = deltas_reader.read(&None)?; + let deltas = deltas_reader.read(None)?; assert_eq!(deltas.len(), 1); assert_eq!( @@ -142,7 +142,7 @@ fn test_list_deltas_from_flushed_session() -> Result<()> { let session_reader = sessions::Reader::open(&gb_repository, &session.unwrap())?; let deltas_reader = deltas::Reader::new(&session_reader); - let deltas = deltas_reader.read(&None)?; + let deltas = deltas_reader.read(None)?; assert_eq!(deltas.len(), 1); assert_eq!( @@ -166,7 +166,7 @@ fn test_list_files_from_current_session() -> Result<()> { let current = gb_repository.get_or_create_current_session()?; let reader = sessions::Reader::open(&gb_repository, ¤t)?; - let files = reader.files(&None)?; + let files = reader.files(None)?; assert_eq!(files.len(), 1); assert_eq!( @@ -191,7 +191,7 @@ fn test_list_files_from_flushed_session() -> Result<()> { gb_repository.get_or_create_current_session()?; let session = gb_repository.flush(&project_repository, None)?.unwrap(); let reader = sessions::Reader::open(&gb_repository, &session)?; - let files = reader.files(&None)?; + let files = reader.files(None)?; assert_eq!(files.len(), 1); assert_eq!( @@ -268,8 +268,8 @@ fn test_remote_syncronization() -> Result<()> { let session_reader = sessions::Reader::open(&case_two.gb_repository, &sessions_two[0])?; let deltas_reader = deltas::Reader::new(&session_reader); - let deltas = deltas_reader.read(&None)?; - let files = session_reader.files(&None)?; + let deltas = deltas_reader.read(None)?; + let files = session_reader.files(None)?; assert_eq!(deltas.len(), 1); assert_eq!(files.len(), 1); assert_eq!( diff --git a/packages/tauri/src/sessions/reader.rs b/packages/tauri/src/sessions/reader.rs index 564c53b9e..776507141 100644 --- a/packages/tauri/src/sessions/reader.rs +++ b/packages/tauri/src/sessions/reader.rs @@ -84,7 +84,7 @@ impl<'reader> SessionReader<'reader> { pub fn files( &self, - paths: &Option>, + paths: Option<&[path::PathBuf]>, ) -> Result> { let files = self.previous_reader.list_files(path::Path::new("wd"))?; let mut files_with_content = HashMap::new(); diff --git a/packages/tauri/src/watcher/handlers/index_handler.rs b/packages/tauri/src/watcher/handlers/index_handler.rs index 461308473..33ef77347 100644 --- a/packages/tauri/src/watcher/handlers/index_handler.rs +++ b/packages/tauri/src/watcher/handlers/index_handler.rs @@ -139,7 +139,7 @@ impl Handler { let deltas_reader = deltas::Reader::new(&session_reader); for (file_path, deltas) in deltas_reader - .read(&None) + .read(None) .context("could not list deltas for session")? { let delta_events = self.index_deltas(project_id, &session.id, &file_path, &deltas)?; diff --git a/packages/tauri/src/watcher/handlers/project_file_change.rs b/packages/tauri/src/watcher/handlers/project_file_change.rs index ad88ed2b2..2b8ec0763 100644 --- a/packages/tauri/src/watcher/handlers/project_file_change.rs +++ b/packages/tauri/src/watcher/handlers/project_file_change.rs @@ -570,7 +570,7 @@ mod test { for session in &mut *sessions_slice { let session_reader = sessions::Reader::open(&gb_repository, session).unwrap(); let deltas_reader = deltas::Reader::new(&session_reader); - let deltas_by_filepath = deltas_reader.read(&None).unwrap(); + let deltas_by_filepath = deltas_reader.read(None).unwrap(); for deltas in deltas_by_filepath.values() { for delta in deltas { delta.operations.iter().for_each(|operation| { @@ -582,7 +582,7 @@ mod test { let reader = sessions::Reader::open(&gb_repository, sessions_slice.first().unwrap()).unwrap(); - let files = reader.files(&None).unwrap(); + let files = reader.files(None).unwrap(); if i == 0 { assert_eq!(files.len(), 0); @@ -656,7 +656,7 @@ mod test { for session in &mut *sessions_slice { let session_reader = sessions::Reader::open(&gb_repository, session).unwrap(); let deltas_reader = deltas::Reader::new(&session_reader); - let deltas_by_filepath = deltas_reader.read(&None).unwrap(); + let deltas_by_filepath = deltas_reader.read(None).unwrap(); for deltas in deltas_by_filepath.values() { for delta in deltas { delta.operations.iter().for_each(|operation| { @@ -668,7 +668,7 @@ mod test { let reader = sessions::Reader::open(&gb_repository, sessions_slice.first().unwrap()).unwrap(); - let files = reader.files(&None).unwrap(); + let files = reader.files(None).unwrap(); if i == 0 { assert_eq!(files.len(), 0); @@ -719,7 +719,7 @@ mod test { let session = gb_repository.get_current_session()?.unwrap(); let session_reader = sessions::Reader::open(&gb_repository, &session).unwrap(); let deltas_reader = deltas::Reader::new(&session_reader); - let deltas_by_filepath = deltas_reader.read(&None).unwrap(); + let deltas_by_filepath = deltas_reader.read(None).unwrap(); for deltas in deltas_by_filepath.values() { for delta in deltas { delta.operations.iter().for_each(|operation| { @@ -729,7 +729,7 @@ mod test { } let reader = sessions::Reader::open(&gb_repository, &session).unwrap(); - let files = reader.files(&None).unwrap(); + let files = reader.files(None).unwrap(); let base_file = files.get(&relative_file_path.to_path_buf()); let mut text: Vec = match base_file {