Skip to content

Commit

Permalink
Fix build by adding trait bounds to existential types
Browse files Browse the repository at this point in the history
  • Loading branch information
MingweiSamuel committed May 19, 2022
1 parent 77ebfc3 commit 6b8d91f
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 13 deletions.
2 changes: 1 addition & 1 deletion hydroflow/src/builder/build/pull_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ where
type PullBuildImpl<'slf, 'ctx, Prev, Func>
where
Prev: PullBuild,
Func: 'slf,
Func: 'slf + FnMut(&Context, &Prev::ItemOut) -> bool,
= std::iter::Filter<Prev::Build<'slf, 'ctx>, impl FnMut(&Prev::ItemOut) -> bool>;

impl<Prev, Func> PullBuild for FilterPullBuild<Prev, Func>
Expand Down
2 changes: 1 addition & 1 deletion hydroflow/src/builder/build/pull_filter_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ where
type PullBuildImpl<'slf, 'ctx, Prev, Func, Out>
where
Prev: PullBuild,
Func: 'slf,
Func: 'slf + FnMut(&Context, Prev::ItemOut) -> Option<Out>,
= std::iter::FilterMap<Prev::Build<'slf, 'ctx>, impl FnMut(Prev::ItemOut) -> Option<Out>>;

impl<Prev, Func, Out> PullBuild for FilterMapPullBuild<Prev, Func>
Expand Down
4 changes: 2 additions & 2 deletions hydroflow/src/builder/build/pull_fold_epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ where
type PullBuildImpl<'slf, 'ctx, Prev, Init, Func, Out>
where
Prev: 'slf + PullBuild,
Init: 'slf,
Func: 'slf,
Init: 'slf + FnMut(&Context) -> Out,
Func: 'slf + FnMut(&Context, Out, Prev::ItemOut) -> Out,
= std::iter::OnceWith<impl FnOnce() -> Out>;

impl<Prev, Init, Func, Out> PullBuild for FoldEpochPullBuild<Prev, Init, Func>
Expand Down
2 changes: 1 addition & 1 deletion hydroflow/src/builder/build/pull_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ where
type PullBuildImpl<'slf, 'ctx, Prev, Func, Out>
where
Prev: PullBuild,
Func: 'slf,
Func: 'slf + FnMut(&Context, Prev::ItemOut) -> Out,
= std::iter::Map<Prev::Build<'slf, 'ctx>, impl FnMut(Prev::ItemOut) -> Out>;

impl<Prev, Func, Out> PullBuild for MapPullBuild<Prev, Func>
Expand Down
2 changes: 1 addition & 1 deletion hydroflow/src/builder/build/push_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ where
type PushBuildImpl<'slf, 'ctx, Next, Func>
where
Next: PushBuild,
Func: 'slf,
Func: 'slf + FnMut(&Context, &Next::ItemIn) -> bool,
= Filter<Next::ItemIn, impl FnMut(&Next::ItemIn) -> bool, Next::Build<'slf, 'ctx>>;

impl<Next, Func> PushBuild for FilterPushBuild<Next, Func>
Expand Down
2 changes: 1 addition & 1 deletion hydroflow/src/builder/build/push_filter_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ where
type PushBuildImpl<'slf, 'ctx, Next, Func, In>
where
Next: PushBuild,
Func: 'slf,
Func: 'slf + FnMut(&Context, In) -> Option<Next::ItemIn>,
= FilterMap<Next::Build<'slf, 'ctx>, impl FnMut(In) -> Option<Next::ItemIn>, In>;

impl<Next, Func, In> PushBuild for FilterMapPushBuild<Next, Func, In>
Expand Down
2 changes: 1 addition & 1 deletion hydroflow/src/builder/build/push_for_each.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ where
#[allow(type_alias_bounds)]
type PushBuildImpl<'slf, 'ctx, Func, In>
where
Func: 'slf,
Func: 'slf + FnMut(&Context, In),
= ForEach<In, impl FnMut(In)>;

impl<Func, In> PushBuild for ForEachPushBuild<Func, In>
Expand Down
2 changes: 1 addition & 1 deletion hydroflow/src/builder/build/push_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ where
type PushBuildImpl<'slf, 'ctx, Next, Func, In>
where
Next: PushBuild,
Func: 'slf,
Func: 'slf + FnMut(&Context, In) -> Next::ItemIn,
= Map<In, Next::ItemIn, impl FnMut(In) -> Next::ItemIn, Next::Build<'slf, 'ctx>>;

impl<Next, Func, In> PushBuild for MapPushBuild<Next, Func, In>
Expand Down
6 changes: 5 additions & 1 deletion hydroflow/src/builder/build/push_partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ where
#[allow(type_alias_bounds)]
type PushBuildImpl<'slf, 'ctx, NextA, NextB, Func>
where
Func: 'slf + FnMut(&Context, &NextA::ItemIn) -> bool,
NextA: PushBuild,
NextB: PushBuild<ItemIn = NextA::ItemIn>,
Func: 'slf,

NextA::OutputHandoffs: Extend<NextB::OutputHandoffs>,
<NextA::OutputHandoffs as Extend<NextB::OutputHandoffs>>::Extended:
PortList<SEND> + PortListSplit<SEND, NextA::OutputHandoffs, Suffix = NextB::OutputHandoffs>,
= Partition<
NextA::ItemIn,
impl FnMut(&NextA::ItemIn) -> bool,
Expand Down
6 changes: 5 additions & 1 deletion hydroflow/src/builder/surface/map_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ use crate::scheduled::context::Context;
use crate::scheduled::flow_graph::NodeId;
use crate::scheduled::state::StateHandle;

type MapScanFunc<Func, State, In, Out> = impl FnMut(&Context, In) -> Out;
type MapScanFunc<Func, State, In, Out>
where
Func: FnMut(&mut State, In) -> Out,
State: Any,
= impl FnMut(&Context, In) -> Out;

fn wrap_func<Func, State, In, Out>(
mut func: Func,
Expand Down
17 changes: 15 additions & 2 deletions hydroflow/src/builder/surface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,26 +190,31 @@ pub trait BaseSurface {
pub type MapNoCtxFn<Prev, Func, Out>
where
Prev: BaseSurface,
Func: FnMut(Prev::ItemOut) -> Out,
= impl FnMut(&Context, Prev::ItemOut) -> Out;

pub type FilterNoCtxFn<Prev, Func>
where
Prev: BaseSurface,
Func: FnMut(&Prev::ItemOut) -> bool,
= impl FnMut(&Context, &Prev::ItemOut) -> bool;

pub type FilterMapNoCtxFn<Prev, Func, Out>
where
Prev: BaseSurface,
Func: FnMut(Prev::ItemOut) -> Option<Out>,
= impl FnMut(&Context, Prev::ItemOut) -> Option<Out>;

pub type InspectMapFunc<Prev, Func>
where
Prev: BaseSurface,
Func: FnMut(&Context, &Prev::ItemOut),
= impl FnMut(&Context, Prev::ItemOut) -> Prev::ItemOut;

pub type InspectMapNoCtxFunc<Prev, Func>
where
Prev: BaseSurface,
Func: FnMut(&Prev::ItemOut),
= impl FnMut(&Context, Prev::ItemOut) -> Prev::ItemOut;

pub trait PullSurface: BaseSurface {
Expand Down Expand Up @@ -443,12 +448,20 @@ pub trait PushSurface: BaseSurface {

pub type ForEachNoCtxFunc<Prev, Func>
where
Prev: BaseSurface,
Prev: PushSurface,
Func: FnMut(Prev::ItemOut),
= impl FnMut(&Context, Prev::ItemOut);

pub type PartitionNoCtxOutput<Prev, Func, NextA, NextB>
where
Prev: BaseSurface,
Prev: PushSurface,
Func: Fn(&Prev::ItemOut) -> bool,
NextA: PushSurfaceReversed<ItemIn = Prev::ItemOut>,
NextB: PushSurfaceReversed<ItemIn = Prev::ItemOut>,

NextA::OutputHandoffs: Extend<NextB::OutputHandoffs>,
<NextA::OutputHandoffs as Extend<NextB::OutputHandoffs>>::Extended:
PortList<SEND> + PortListSplit<SEND, NextA::OutputHandoffs, Suffix = NextB::OutputHandoffs>,
= push_partition::PartitionPushSurfaceReversed<
NextA,
NextB,
Expand Down

0 comments on commit 6b8d91f

Please sign in to comment.