Comments (2)
embedded-nrf24l01 driver
Type state for the IO is an interesting choice.
You have to do the option dance, which is what you are already doing. You don't need the RefCell
though; you should be able to use Option.take
. Here's an Option.take
version with no unwraps / panics:
fn foo(driver: &mut Option<Driver<StandBy>>) {
// start dance
if let Some(standby) = driver.take() {
// change state
let read = standby.read();
// do stuff with `read`
// change state
let standby = read.standby();
// end dance
*driver = Some(standby);
}
}
use std::marker::PhantomData;
struct Driver<STATE> {
_state: PhantomData<STATE>,
}
impl<S> Driver<S> {
fn read(self) -> Driver<Read> {
Driver {
_state: PhantomData,
}
}
fn standby(self) -> Driver<StandBy> {
Driver {
_state: PhantomData,
}
}
}
struct StandBy;
struct Read;
from rtic.
Thanks! This approach works fine. Indeed, the use of RefCell was redundant here, Option.take does the same thing. Closing the issue...
from rtic.
Related Issues (20)
- timeout_after memory usage HOT 1
- nested lock() can allow access to unlocked resources HOT 5
- `docs.rs` page for `rtic` v2.1.1 is not available
- broken usage example for i2c sharing HOT 2
- Software/Hardware Task interfaction with RTIC v2 HOT 2
- How to invoke code before RTIC main part. HOT 1
- Docs: Examples are broken and not showing HOT 3
- `atomic-polyfill` is deprecated
- rtic_monotonics 2.0 not in crates.io??? HOT 5
- Consider adding a hook to run code at the beginning of the entry point HOT 3
- SPI devices on shared bus (embedded-hal-bus) HOT 3
- Locked Status with Multiple Shared Resources HOT 2
- Software tasks and the stack HOT 2
- Support for embedded_alloc
- Call to SCB::sys_reset() results in locked up core. HOT 3
- rtic-monotonic on stm32 TIM20 or TIM17 HOT 2
- How to get the time stamp in a RTIC Rust Embedded application HOT 1
- Proplems while setting up rtic 2.1.1 HOT 2
- Multicore Support HOT 3
- How can I share the spawn handle? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rtic.