mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-07 20:39:04 +03:00
fmt
This commit is contained in:
parent
5b2ee63f80
commit
dfb6a2f7fc
@ -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 {
|
||||
|
@ -111,25 +111,26 @@ impl<K: Clone + Debug + Default + Ord, V: Clone + Debug> TreeMap<K, V> {
|
||||
self.0 = new_tree;
|
||||
}
|
||||
|
||||
pub fn get_from_while<'tree, F>(
|
||||
&'tree self,
|
||||
from: &'tree K,
|
||||
mut f: F,
|
||||
) -> impl Iterator<Item = (&K, &V)> + '_
|
||||
where
|
||||
F: FnMut(&K, &K, &V) -> bool + 'tree,
|
||||
{
|
||||
let mut cursor = self.0.cursor::<MapKeyRef<'_, K>>();
|
||||
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<Item = (&K, &V)> + '_
|
||||
where
|
||||
F: FnMut(&K, &K, &V) -> bool + 'tree,
|
||||
{
|
||||
let mut cursor = self.0.cursor::<MapKeyRef<'_, K>>();
|
||||
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<F, T>(&mut self, key: &K, f: F) -> Option<T>
|
||||
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::<Vec<_>>();
|
||||
let result = map
|
||||
.get_from_while(&"ba", |key, _| key.starts_with(&"ba"))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
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::<Vec<_>>();
|
||||
let result = map
|
||||
.get_from_while(&"c", |key, _| key.starts_with(&"c"))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
assert_eq!(result.len(), 1);
|
||||
assert!(result.iter().find(|(k, _)| k == &&"c").is_some());
|
||||
|
Loading…
Reference in New Issue
Block a user