Browse Source

itemtransaction action takes boxed value

pull/80/head
jake 3 years ago
parent
commit
21df9a9340
  1. 25
      src/ship/items/transaction.rs

25
src/ship/items/transaction.rs

@ -38,11 +38,8 @@ impl<'a, EG: EntityGateway> ItemTransactionActions<'a, EG> {
} }
} }
pub fn action<A: ItemAction<EG> + 'static>(&mut self, action: A) {
//pub fn action<A: Into<Box<dyn ItemAction<EG>>>>(&mut self, action: A) {
//pub fn action(&mut self, action: impl ItemAction<EG>) {
self.action_queue.push(Box::new(action))
//self.action_queue.push(action.into())
pub fn action(&mut self, action: Box<dyn ItemAction<EG>>) {
self.action_queue.push(action)
} }
} }
@ -226,9 +223,9 @@ mod test {
let result = ItemTransaction::new(&item_manager, 12) let result = ItemTransaction::new(&item_manager, 12)
.act(|it, k| { .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 { if *k == 99 {
return Err(DummyError::Error) return Err(DummyError::Error)
} }
@ -300,9 +297,9 @@ mod test {
let result = ItemTransaction::new(&item_manager, 12) let result = ItemTransaction::new(&item_manager, 12)
.act(|it, _| -> Result<(), _> { .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) Err(DummyError::Error)
}) })
.commit(&mut item_manager, &mut entity_gateway) .commit(&mut item_manager, &mut entity_gateway)
@ -368,9 +365,9 @@ mod test {
let result = ItemTransaction::new(&item_manager, 12) let result = ItemTransaction::new(&item_manager, 12)
.act(|it, _| -> Result<_, DummyError> { .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(()) Ok(())
}) })
.commit(&mut item_manager, &mut entity_gateway) .commit(&mut item_manager, &mut entity_gateway)

Loading…
Cancel
Save