From 71dc20671bf548bbfb8fd37e3db69a89303bbe8d Mon Sep 17 00:00:00 2001 From: jake Date: Wed, 27 Apr 2022 20:56:39 -0600 Subject: [PATCH] remove boxes from ItemStateAction structs to remove need for static lifetimes --- src/ship/items/state.rs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/ship/items/state.rs b/src/ship/items/state.rs index d5a46f5..b31ed9c 100644 --- a/src/ship/items/state.rs +++ b/src/ship/items/state.rs @@ -79,9 +79,11 @@ where S: Send + Sync, E: Send + Sync, { - fn act(self, f: F) -> ItemActionStage, F, S, E> + pub fn act(self, f: F) -> ItemActionStage, F, Fut, S, E> where - F: Fn(S, ()) -> Pin> + Send>> + Send + Sync + //F: FnOnce(S, ()) -> Pin> + Send>> + Send + Sync + F: Fn(S, ()) -> Fut + Send + Sync, + Fut: Future> + Send { ItemActionStage { _s: Default::default(), @@ -92,10 +94,12 @@ where } } -struct ItemActionStage +pub struct ItemActionStage where P: ItemAction, - F: Fn(S, P::Output) -> Pin> + Send>> + Send + Sync, + F: Fn(S, P::Output) -> Fut + Send + Sync, + Fut: Future> + Send, + //F: FnOnce(S, P::Output) -> Pin> + Send>> + Send + Sync, { _s: std::marker::PhantomData, _e: std::marker::PhantomData, @@ -104,10 +108,12 @@ where } #[async_trait::async_trait] -impl ItemAction for ItemActionStage +impl ItemAction for ItemActionStage where P: ItemAction + ItemAction + Send + Sync, - F: Fn(S, P::Output) -> Pin> + Send>> + Send + Sync, + //F: FnOnce(S, P::Output) -> Pin> + Send>> + Send + Sync, + F: Fn(S, P::Output) -> Fut + Send + Sync, + Fut: Future> + Send, S: Send + Sync, P::Output: Send + Sync, E: Send + Sync, @@ -129,20 +135,23 @@ where } } -impl ItemActionStage +impl ItemActionStage where P: ItemAction + Send + Sync, - F: Fn(S, P::Output) -> Pin> + Send>> + Send + Sync, + F: Fn(S, P::Output) -> Fut + Send + Sync, + Fut: Future> + Send, S: Send + Sync, P::Output: Send + Sync, E: Send + Sync, O: Send + Sync, P::Error: Send + Sync, { - fn act(self, g: G) -> ItemActionStage, G, S, E> + pub fn act(self, g: G) -> ItemActionStage, G, GFut, S, E> where S: Send + Sync, - G: Fn(S, as ItemAction>::Output) -> Pin> + Send>> + Send + Sync, + //G: FnOnce(S, as ItemAction>::Output) -> Pin> + Send>> + Send + Sync, + G: Fn(S, as ItemAction>::Output) -> GFut + Send + Sync, + GFut: Future> + Send, O2: Send + Sync, { ItemActionStage {