os-trait
os-trait provides a unified trait layer for adapting multiple RTOS implementations to embedded Rust HALs.
It makes embedded Rust code more portable, testable, and OS‑agnostic by standardizing common OS primitives such as mutexes, delays, timeouts, notifier, and thread yielding.
This crate integrates with several foundational components of the embedded Rust ecosystem:
timeout-trait— timeout abstractionsembedded-hal— uses theDelayNstraitmutex— usesBlockingMutexandRawMutex
📦 Usage
use ;
⚙️ Cargo Features
| Feature | Default | Description |
|---|---|---|
alloc |
✔️ | Enables allocation support |
std |
❌ | Enables std for unit testing |
std-custom-mutex |
❌ | Use BlockingMutex instead of std::sync::Mutex in std environments |
🧩 Implementing Your Own OS
Implement the OsInterface trait and provide:
- A
RawMuteximplementation - A
Notifierimplementation - A
DelayNsimplementation - A timeout implementation
- A thread‑yielding function
Once implemented, your OS becomes compatible with any HAL or driver that depends on os-trait.
For a full implementation example, see os_trait_impls.rs for FreeRTOS. Basic examples are available in os_impls.rs.
🔖 Keywords
embedded rust · rtos · hal · mutex · delay · timeout · portability · no_std · embedded-hal · traits