Skip to content

Commit

Permalink
Expand lifetimes of SplitBuilder (#36)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael X. Grey <[email protected]>
  • Loading branch information
mxgrey authored Dec 4, 2024
1 parent d074da8 commit ca95c2d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
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

0 comments on commit ca95c2d

Please sign in to comment.