From dfb6a2f7fca54d22b42ded92dc9fc1fca4cbfcdc Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Thu, 11 May 2023 12:02:25 -0700 Subject: [PATCH] fmt --- crates/collab/src/db.rs | 18 ++++++++++--- crates/sum_tree/src/tree_map.rs | 45 ++++++++++++++++++--------------- 2 files changed, 39 insertions(+), 24 deletions(-) diff --git a/crates/collab/src/db.rs b/crates/collab/src/db.rs index f5175a16a9..1047b207b9 100644 --- a/crates/collab/src/db.rs +++ b/crates/collab/src/db.rs @@ -2484,11 +2484,21 @@ impl Database { .filter( worktree_repository_statuses::Column::ProjectId .eq(project_id) - .and(worktree_repository_statuses::Column::WorktreeId.eq(worktree_id)) - .and(worktree_repository_statuses::Column::WorkDirectoryId.eq(repository.work_directory_id as i64)) .and( - worktree_repository_statuses::Column::RepoPath - .is_in(repository.removed_worktree_repo_paths.iter().map(String::as_str)), + worktree_repository_statuses::Column::WorktreeId + .eq(worktree_id), + ) + .and( + worktree_repository_statuses::Column::WorkDirectoryId + .eq(repository.work_directory_id as i64), + ) + .and( + worktree_repository_statuses::Column::RepoPath.is_in( + repository + .removed_worktree_repo_paths + .iter() + .map(String::as_str), + ), ), ) .set(worktree_repository_statuses::ActiveModel { diff --git a/crates/sum_tree/src/tree_map.rs b/crates/sum_tree/src/tree_map.rs index e59b05f00f..b18af3633a 100644 --- a/crates/sum_tree/src/tree_map.rs +++ b/crates/sum_tree/src/tree_map.rs @@ -111,25 +111,26 @@ impl TreeMap { self.0 = new_tree; } + pub fn get_from_while<'tree, F>( + &'tree self, + from: &'tree K, + mut f: F, + ) -> impl Iterator + '_ + where + F: FnMut(&K, &K, &V) -> bool + 'tree, + { + let mut cursor = self.0.cursor::>(); + let from_key = MapKeyRef(Some(from)); + cursor.seek(&from_key, Bias::Left, &()); - pub fn get_from_while<'tree, F>(&'tree self, from: &'tree K, mut f: F) -> impl Iterator + '_ - where - F: FnMut(&K, &K, &V) -> bool + 'tree, - { - let mut cursor = self.0.cursor::>(); - let from_key = MapKeyRef(Some(from)); - cursor.seek(&from_key, Bias::Left, &()); - - iter::from_fn(move || { - let result = cursor.item().and_then(|item| { - (f(from, &item.key, &item.value)) - .then(|| (&item.key, &item.value)) - }); - cursor.next(&()); - result - }) - } - + iter::from_fn(move || { + let result = cursor.item().and_then(|item| { + (f(from, &item.key, &item.value)).then(|| (&item.key, &item.value)) + }); + cursor.next(&()); + result + }) + } pub fn update(&mut self, key: &K, f: F) -> Option where @@ -384,13 +385,17 @@ mod tests { map.insert("baaab", 4); map.insert("c", 5); - let result = map.get_from_while(&"ba", |key, _| key.starts_with(&"ba")).collect::>(); + let result = map + .get_from_while(&"ba", |key, _| key.starts_with(&"ba")) + .collect::>(); assert_eq!(result.len(), 2); assert!(result.iter().find(|(k, _)| k == &&"baa").is_some()); assert!(result.iter().find(|(k, _)| k == &&"baaab").is_some()); - let result = map.get_from_while(&"c", |key, _| key.starts_with(&"c")).collect::>(); + let result = map + .get_from_while(&"c", |key, _| key.starts_with(&"c")) + .collect::>(); assert_eq!(result.len(), 1); assert!(result.iter().find(|(k, _)| k == &&"c").is_some());