forked from esrlabs/chipmunk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[esrlabs#1966] Basic skeleton with Componets and Commands
- Loading branch information
1 parent
28fb012
commit 43aca49
Showing
9 changed files
with
455 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use crate::components::cleanable; | ||
use crate::errors::BuildError; | ||
use cleanable::Cleanable; | ||
|
||
use super::Command; | ||
|
||
pub struct Clean { | ||
component: Cleanable | ||
} | ||
|
||
impl Clean { | ||
pub fn new(component_name: String) -> Result<Self, BuildError> { | ||
let component = cleanable::Cleanable::new(component_name)?; | ||
Ok(Self { component }) | ||
} | ||
} | ||
|
||
impl Command for Clean { | ||
fn run(&self) { | ||
// Clean the component | ||
self.component.clean(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
mod clean; | ||
|
||
pub use clean::Clean; | ||
|
||
pub trait Command { | ||
fn run(&self); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use super::Component; | ||
|
||
const COMPONENT_NAME:&str = "Bindings"; | ||
|
||
pub struct Bindings {} | ||
|
||
impl Bindings { | ||
pub fn clean(&self) { | ||
// Bindings knows how to clear itself | ||
} | ||
} | ||
|
||
impl Component for Bindings { | ||
fn new() -> Self { | ||
Self {} | ||
} | ||
|
||
fn name(&self) -> &str { | ||
COMPONENT_NAME | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use crate::errors::{BuildError, BuildErrorTypes}; | ||
|
||
use super::Component; | ||
use super::bindings::Bindings; | ||
|
||
pub enum Cleanable { | ||
Bindings(Bindings) | ||
} | ||
|
||
impl Cleanable { | ||
pub fn new(component_name: String) -> Result<Cleanable, BuildError> { | ||
match component_name.as_str() { | ||
"bindings" => Ok(Cleanable::Bindings(Bindings::new())), | ||
_ => Err(BuildError::new(BuildErrorTypes::UnknownComponent(component_name))) | ||
} | ||
} | ||
|
||
pub fn name(&self) -> &str { | ||
match self { | ||
Cleanable::Bindings(bindings) => { bindings.name() } | ||
} | ||
} | ||
|
||
pub fn clean(&self) { | ||
match self { | ||
Cleanable::Bindings(bindings) => { bindings.clean() } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
mod bindings; | ||
|
||
pub mod cleanable; | ||
|
||
trait Component { | ||
fn new() -> Self; | ||
fn name(&self) -> &str; | ||
} |
Oops, something went wrong.