Expand description
Traits used to wait and timeout in a no-std embedded system.
§Features
std: Disabled by default.
§Usage
- New a
WaiterorTimedWaiterimplementation. - Call
start()to get aWaiterStatusimplementation. - Call
timeout()to check if the time limit expires.Interval::intervalis usually called intimeout()before the time limit expires. It also depends on your implementation.
- Call
restart()to reset the timeout condition if necessary.
§Example
use waiter_trait::prelude::*;
fn foo(waiter: impl Waiter) {
let mut t = waiter.start();
loop {
// Wait for something.
// Reset if it's necessary.
t.restart();
if t.timeout() {
break;
}
}
}§Pre-implemented
StdWaiterandStdInterval: Need thestdfeature enabled.NonInterval: implementsIntervalthat does nothing.TickDelay: implementsDelayNs
§Implement Your Own
For developers, you can choose one of the following options.
- Implement
WaiterorTimedWaiter, andWaiterStatusthen use them. - Implement
TickInstantthen useTickWaiterorTimedTickWaiter.- Simply give
NonIntervaltoWaiter, If you don’t need interval. In this way, you can also useDelayNsorsleepseparately. - Or you can implement
Intervaland use it.
- Simply give
- Using
Counter, if you don’t have any tick source.
Re-exports§
pub use fugit;
Modules§
Structs§
- Counter
- The timeout condition is independent of time
and is determined solely by the number of times
timeout()is called. - Counter
Instance - NonInterval
Intervalimplementation that does nothing- StdInterval
Intervalimplementation forstd.- StdWaiter
Waiterimplementation forstd.- StdWaiter
Status WaiterStatusimplementation forstd.- Tick
Delay DelayNsimplementation- Tick
Waiter Waiterimplementation for embedded system.- Tick
Waiter Status - Timed
Tick Waiter Waiterimplementation for embedded system.- Timed
Tick Waiter Status
Traits§
- DelayNs
- Delay with up to nanosecond precision.
- Interval
- It is usually called at
WaiterStatus::timeoutbefore the time limit expires. It can be implemented foryield,sleepor do nothing. - Num
- Tick
Instant - Timed
Waiter - The difference from
Waiteris that it supports setting timeout atstart(). - Waiter
- Waiter
Status
Type Aliases§
- Micros
Duration U32 - Alias for microsecond duration (
u32backing storage)