WIP Impl Action
This commit is contained in:
parent
23fed5b6ca
commit
b8bac1142c
28 changed files with 363 additions and 58 deletions
|
|
@ -2,6 +2,15 @@ use std::error::Error;
|
|||
use std::fmt::Display;
|
||||
use resources::Resource;
|
||||
|
||||
pub trait Action {
|
||||
fn run(&self) -> Result<(), Box<Error>>;
|
||||
}
|
||||
|
||||
pub trait SymbolRunner {
|
||||
fn run_symbol(&self, symbol: &Symbol) -> Result<(), Box<Error>>;
|
||||
}
|
||||
|
||||
// Symbol
|
||||
pub trait Symbol: Display {
|
||||
fn target_reached(&self) -> Result<bool, Box<Error>>;
|
||||
fn execute(&self) -> Result<(), Box<Error>>;
|
||||
|
|
@ -11,6 +20,43 @@ pub trait Symbol: Display {
|
|||
fn provides(&self) -> Option<Vec<Resource>> {
|
||||
None
|
||||
}
|
||||
fn as_action<'a>(&'a self, runner: &'a SymbolRunner) -> Box<Action + 'a>;
|
||||
fn into_action<'a>(self: Box<Self>, runner: &'a SymbolRunner) -> Box<Action + 'a> where Self: 'a;
|
||||
}
|
||||
|
||||
// SymbolAction
|
||||
struct SymbolAction<'a, S: Symbol + 'a> {
|
||||
runner: &'a SymbolRunner,
|
||||
symbol: &'a S
|
||||
}
|
||||
|
||||
impl<'a, S: Symbol> SymbolAction<'a, S> {
|
||||
fn new(runner: &'a SymbolRunner, symbol: &'a S) -> Self {
|
||||
Self { runner: runner, symbol: symbol }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, S: Symbol> Action for SymbolAction<'a, S> {
|
||||
fn run(&self) -> Result<(), Box<Error>> {
|
||||
self.runner.run_symbol(self.symbol)
|
||||
}
|
||||
}
|
||||
|
||||
struct OwnedSymbolAction<'a, S: Symbol + 'a> {
|
||||
runner: &'a SymbolRunner,
|
||||
symbol: S
|
||||
}
|
||||
|
||||
impl<'a, S: Symbol + 'a> OwnedSymbolAction<'a, S> {
|
||||
fn new(runner: &'a SymbolRunner, symbol: S) -> Self {
|
||||
Self { runner: runner, symbol: symbol }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, S: Symbol + 'a> Action for OwnedSymbolAction<'a, S> {
|
||||
fn run(&self) -> Result<(), Box<Error>> {
|
||||
self.runner.run_symbol(&self.symbol)
|
||||
}
|
||||
}
|
||||
|
||||
pub mod acme;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue