Skip to content

Commit ca95c2d

Browse files
authored
Expand lifetimes of SplitBuilder (#36)
Signed-off-by: Michael X. Grey <greyxmike@gmail.com>
1 parent d074da8 commit ca95c2d

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

src/chain.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ impl<'w, 's, 'a, 'b, T: 'static + Send + Sync> Chain<'w, 's, 'a, 'b, T> {
608608
/// will insert a split operation and provide your `build` function with the
609609
/// [`SplitBuilder`] for it. This returns the return value of your build
610610
/// function.
611-
pub fn split<U>(self, build: impl FnOnce(SplitBuilder<T>) -> U) -> U
611+
pub fn split<U>(self, build: impl FnOnce(SplitBuilder<'w, 's, 'a, 'b, T>) -> U) -> U
612612
where
613613
T: Splittable,
614614
{
@@ -644,7 +644,10 @@ impl<'w, 's, 'a, 'b, T: 'static + Send + Sync> Chain<'w, 's, 'a, 'b, T> {
644644
/// ```text
645645
/// .map_block(SplitAsList::new).split(build)
646646
/// ```
647-
pub fn split_as_list<U>(self, build: impl FnOnce(SplitBuilder<SplitAsList<T>>) -> U) -> U
647+
pub fn split_as_list<U>(
648+
self,
649+
build: impl FnOnce(SplitBuilder<'w, 's, 'a, 'b, SplitAsList<T>>) -> U,
650+
) -> U
648651
where
649652
T: IntoIterator,
650653
T::Item: 'static + Send + Sync,
@@ -1026,7 +1029,10 @@ where
10261029
/// ```text
10271030
/// .map_block(SplitAsMap::new).split(build)
10281031
/// ```
1029-
pub fn split_as_map<U>(self, build: impl FnOnce(SplitBuilder<SplitAsMap<K, V, T>>) -> U) -> U {
1032+
pub fn split_as_map<U>(
1033+
self,
1034+
build: impl FnOnce(SplitBuilder<'w, 's, 'a, 'b, SplitAsMap<K, V, T>>) -> U,
1035+
) -> U {
10301036
self.map_block(SplitAsMap::new).split(build)
10311037
}
10321038

src/chain/split.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,22 @@ impl<K> MapSplitKey<K> {
566566
_ => None,
567567
}
568568
}
569+
570+
pub fn next(this: &Option<Self>) -> Option<Self> {
571+
match this {
572+
Some(key) => {
573+
match key {
574+
// Give the next key in the sequence
575+
MapSplitKey::Sequential(index) => Some(MapSplitKey::Sequential(index + 1)),
576+
// For an arbitrary map we don't know what would follow a specific key, so
577+
// just stop iterating. This should never be reached in practice anyway.
578+
MapSplitKey::Specific(_) => None,
579+
MapSplitKey::Remaining => None,
580+
}
581+
}
582+
None => Some(MapSplitKey::Sequential(0)),
583+
}
584+
}
569585
}
570586

571587
impl<K> From<K> for MapSplitKey<K> {
@@ -637,19 +653,7 @@ where
637653
}
638654

639655
fn next(key: &Option<Self::Key>) -> Option<Self::Key> {
640-
match key {
641-
Some(key) => {
642-
match key {
643-
// Give the next key in the sequence
644-
MapSplitKey::Sequential(index) => Some(MapSplitKey::Sequential(index + 1)),
645-
// For an arbitrary map we don't know what would follow a specific key, so
646-
// just stop iterating. This should never be reached in practice anyway.
647-
MapSplitKey::Specific(_) => None,
648-
MapSplitKey::Remaining => None,
649-
}
650-
}
651-
None => Some(MapSplitKey::Sequential(0)),
652-
}
656+
MapSplitKey::next(key)
653657
}
654658

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

0 commit comments

Comments
 (0)