Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand lifetimes of SplitBuilder #36

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ impl<'w, 's, 'a, 'b, T: 'static + Send + Sync> Chain<'w, 's, 'a, 'b, T> {
/// will insert a split operation and provide your `build` function with the
/// [`SplitBuilder`] for it. This returns the return value of your build
/// function.
pub fn split<U>(self, build: impl FnOnce(SplitBuilder<T>) -> U) -> U
pub fn split<U>(self, build: impl FnOnce(SplitBuilder<'w, 's, 'a, 'b, T>) -> U) -> U
where
T: Splittable,
{
Expand Down Expand Up @@ -644,7 +644,10 @@ impl<'w, 's, 'a, 'b, T: 'static + Send + Sync> Chain<'w, 's, 'a, 'b, T> {
/// ```text
/// .map_block(SplitAsList::new).split(build)
/// ```
pub fn split_as_list<U>(self, build: impl FnOnce(SplitBuilder<SplitAsList<T>>) -> U) -> U
pub fn split_as_list<U>(
self,
build: impl FnOnce(SplitBuilder<'w, 's, 'a, 'b, SplitAsList<T>>) -> U,
) -> U
where
T: IntoIterator,
T::Item: 'static + Send + Sync,
Expand Down Expand Up @@ -1026,7 +1029,10 @@ where
/// ```text
/// .map_block(SplitAsMap::new).split(build)
/// ```
pub fn split_as_map<U>(self, build: impl FnOnce(SplitBuilder<SplitAsMap<K, V, T>>) -> U) -> U {
pub fn split_as_map<U>(
self,
build: impl FnOnce(SplitBuilder<'w, 's, 'a, 'b, SplitAsMap<K, V, T>>) -> U,
) -> U {
self.map_block(SplitAsMap::new).split(build)
}

Expand Down
30 changes: 17 additions & 13 deletions src/chain/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,22 @@ impl<K> MapSplitKey<K> {
_ => None,
}
}

pub fn next(this: &Option<Self>) -> Option<Self> {
match this {
Some(key) => {
match key {
// Give the next key in the sequence
MapSplitKey::Sequential(index) => Some(MapSplitKey::Sequential(index + 1)),
// For an arbitrary map we don't know what would follow a specific key, so
// just stop iterating. This should never be reached in practice anyway.
MapSplitKey::Specific(_) => None,
MapSplitKey::Remaining => None,
}
}
None => Some(MapSplitKey::Sequential(0)),
}
}
}

impl<K> From<K> for MapSplitKey<K> {
Expand Down Expand Up @@ -637,19 +653,7 @@ where
}

fn next(key: &Option<Self::Key>) -> Option<Self::Key> {
match key {
Some(key) => {
match key {
// Give the next key in the sequence
MapSplitKey::Sequential(index) => Some(MapSplitKey::Sequential(index + 1)),
// For an arbitrary map we don't know what would follow a specific key, so
// just stop iterating. This should never be reached in practice anyway.
MapSplitKey::Specific(_) => None,
MapSplitKey::Remaining => None,
}
}
None => Some(MapSplitKey::Sequential(0)),
}
MapSplitKey::next(key)
}

fn split(self, mut dispatcher: SplitDispatcher<'_, Self::Key, Self::Item>) -> OperationResult {
Expand Down
Loading