Strategy Design Pattern and RTIC
hanusek opened this issue · comments
Hello!
I am a newbie in Embedded Rust and RTIC framework.
I would like to implement a design pattern - Strategy or classic pointer to the function.
I created this trait:
trait OperationStrategy
{
fn operate(&mut self);
}
and main struct
struct Card<T: OperationStrategy> {
strategy: T,
}
impl<T: OperationStrategy> Card<T> {
pub fn new(strategy: T) -> Self {
Self { strategy }
}
pub fn operate(&mut self) {
self.strategy.operate();
}
}
Rust Playground:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=3a24cfddcbbdb9f150209686c606e7ec
Embedded Rust (no_std
) hasn't Box
, Arc
and Mutex
.
I have a problem with adding the struct Card
to Shared
.
#[shared]
struct Shared {}
How to fix it?
Please Help
My github repo with code.
My platform: STM32F103
I implemented two solutions.
https://github.com/hanusek/rtic-strategy-pattern/tree/solution1-enum
https://github.com/hanusek/rtic-strategy-pattern/tree/solution2-fnptr
What do you think?
If these two solutions work for you, great! We discussed this briefly during previous week's meeting, and some opinions came out of it, but nobody had tried this pattern so not much to draw from it.
If there is something else to do here, please reopen