From 21df9a934018a9bb83c33d7c8eda7cf0efc25f32 Mon Sep 17 00:00:00 2001 From: jake Date: Wed, 13 Oct 2021 23:56:42 -0600 Subject: [PATCH] itemtransaction action takes boxed value --- src/ship/items/transaction.rs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/ship/items/transaction.rs b/src/ship/items/transaction.rs index a161a2a..805f6d1 100644 --- a/src/ship/items/transaction.rs +++ b/src/ship/items/transaction.rs @@ -38,11 +38,8 @@ impl<'a, EG: EntityGateway> ItemTransactionActions<'a, EG> { } } - pub fn action + 'static>(&mut self, action: A) { - //pub fn action>>>(&mut self, action: A) { - //pub fn action(&mut self, action: impl ItemAction) { - self.action_queue.push(Box::new(action)) - //self.action_queue.push(action.into()) + pub fn action(&mut self, action: Box>) { + self.action_queue.push(action) } } @@ -226,9 +223,9 @@ mod test { let result = ItemTransaction::new(&item_manager, 12) .act(|it, k| { - it.action(DummyAction1 {name: "asdf".into()}); - it.action(DummyAction2 {value: 11}); - it.action(DummyAction2 {value: *k}); + it.action(Box::new(DummyAction1 {name: "asdf".into()})); + it.action(Box::new(DummyAction2 {value: 11})); + it.action(Box::new(DummyAction2 {value: *k})); if *k == 99 { return Err(DummyError::Error) } @@ -300,9 +297,9 @@ mod test { let result = ItemTransaction::new(&item_manager, 12) .act(|it, _| -> Result<(), _> { - it.action(DummyAction1 {}); - it.action(DummyAction2 {}); - it.action(DummyAction2 {}); + it.action(Box::new(DummyAction1 {})); + it.action(Box::new(DummyAction2 {})); + it.action(Box::new(DummyAction2 {})); Err(DummyError::Error) }) .commit(&mut item_manager, &mut entity_gateway) @@ -368,9 +365,9 @@ mod test { let result = ItemTransaction::new(&item_manager, 12) .act(|it, _| -> Result<_, DummyError> { - it.action(DummyAction1 {}); - it.action(DummyAction2 {}); - it.action(DummyAction2 {}); + it.action(Box::new(DummyAction1 {})); + it.action(Box::new(DummyAction2 {})); + it.action(Box::new(DummyAction2 {})); Ok(()) }) .commit(&mut item_manager, &mut entity_gateway)