Browse Source

remove boxes from ItemStateAction structs to remove need for static lifetimes

pull/112/head
jake 3 years ago
committed by andy
parent
commit
e58aff7042
  1. 29
      src/ship/items/state.rs

29
src/ship/items/state.rs

@ -79,9 +79,11 @@ where
S: Send + Sync, S: Send + Sync,
E: Send + Sync, E: Send + Sync,
{ {
fn act<O, F>(self, f: F) -> ItemActionStage<O, ItemStateAction<T, S, E>, F, S, E>
pub fn act<O, F, Fut>(self, f: F) -> ItemActionStage<O, ItemStateAction<T, S, E>, F, Fut, S, E>
where where
F: Fn(S, ()) -> Pin<Box<dyn Future<Output=Result<(S, O), E>> + Send>> + Send + Sync
//F: FnOnce(S, ()) -> Pin<Box<dyn Future<Output=Result<(S, O), E>> + Send>> + Send + Sync
F: Fn(S, ()) -> Fut + Send + Sync,
Fut: Future<Output=Result<(S, O), E>> + Send
{ {
ItemActionStage { ItemActionStage {
_s: Default::default(), _s: Default::default(),
@ -92,10 +94,12 @@ where
} }
} }
struct ItemActionStage<O, P, F, S, E>
pub struct ItemActionStage<O, P, F, Fut, S, E>
where where
P: ItemAction, P: ItemAction,
F: Fn(S, P::Output) -> Pin<Box<dyn Future<Output=Result<(S, O) , E>> + Send>> + Send + Sync,
F: Fn(S, P::Output) -> Fut + Send + Sync,
Fut: Future<Output=Result<(S, O) , E>> + Send,
//F: FnOnce(S, P::Output) -> Pin<Box<dyn Future<Output=Result<(S, O) , E>> + Send>> + Send + Sync,
{ {
_s: std::marker::PhantomData<S>, _s: std::marker::PhantomData<S>,
_e: std::marker::PhantomData<E>, _e: std::marker::PhantomData<E>,
@ -104,10 +108,12 @@ where
} }
#[async_trait::async_trait] #[async_trait::async_trait]
impl<O, P: ItemAction, F, S, E> ItemAction for ItemActionStage<O, P, F, S, E>
impl<O, P: ItemAction, F, Fut, S, E> ItemAction for ItemActionStage<O, P, F, Fut, S, E>
where where
P: ItemAction + ItemAction<Start = S, Error = E> + Send + Sync, P: ItemAction + ItemAction<Start = S, Error = E> + Send + Sync,
F: Fn(S, P::Output) -> Pin<Box<dyn Future<Output=Result<(S, O), E>> + Send>> + Send + Sync,
//F: FnOnce(S, P::Output) -> Pin<Box<dyn Future<Output=Result<(S, O), E>> + Send>> + Send + Sync,
F: Fn(S, P::Output) -> Fut + Send + Sync,
Fut: Future<Output=Result<(S, O), E>> + Send,
S: Send + Sync, S: Send + Sync,
P::Output: Send + Sync, P::Output: Send + Sync,
E: Send + Sync, E: Send + Sync,
@ -129,20 +135,23 @@ where
} }
} }
impl<O, P: ItemAction, F, S, E> ItemActionStage<O, P, F, S, E>
impl<O, P: ItemAction, F, Fut, S, E> ItemActionStage<O, P, F, Fut, S, E>
where where
P: ItemAction<Start = S, Error = E> + Send + Sync, P: ItemAction<Start = S, Error = E> + Send + Sync,
F: Fn(S, P::Output) -> Pin<Box<dyn Future<Output=Result<(S, O), E>> + Send>> + Send + Sync,
F: Fn(S, P::Output) -> Fut + Send + Sync,
Fut: Future<Output=Result<(S, O), E>> + Send,
S: Send + Sync, S: Send + Sync,
P::Output: Send + Sync, P::Output: Send + Sync,
E: Send + Sync, E: Send + Sync,
O: Send + Sync, O: Send + Sync,
P::Error: Send + Sync, P::Error: Send + Sync,
{ {
fn act<O2, G>(self, g: G) -> ItemActionStage<O2, ItemActionStage<O, P, F, S, E>, G, S, E>
pub fn act<O2, G, GFut>(self, g: G) -> ItemActionStage<O2, ItemActionStage<O, P, F, Fut, S, E>, G, GFut, S, E>
where where
S: Send + Sync, S: Send + Sync,
G: Fn(S, <ItemActionStage<O, P, F, S, E> as ItemAction>::Output) -> Pin<Box<dyn Future<Output=Result<(S, O2), E>> + Send>> + Send + Sync,
//G: FnOnce(S, <ItemActionStage<O, P, F, S, E> as ItemAction>::Output) -> Pin<Box<dyn Future<Output=Result<(S, O2), E>> + Send>> + Send + Sync,
G: Fn(S, <ItemActionStage<O, P, F, Fut, S, E> as ItemAction>::Output) -> GFut + Send + Sync,
GFut: Future<Output=Result<(S, O2), E>> + Send,
O2: Send + Sync, O2: Send + Sync,
{ {
ItemActionStage { ItemActionStage {

Loading…
Cancel
Save