pub trait OsInterface: Send + Sync {
type RawMutex: ConstInit + RawMutex;
type NotifyBuilder: NotifyBuilder;
type Timeout: TimeoutNs;
// Required methods
fn yield_thread();
fn delay() -> impl DelayNs;
// Provided methods
fn mutex<T>(d: T) -> Mutex<Self, T> { ... }
fn notifier() -> (impl Notifier, impl NotifyWaiter) { ... }
}Expand description
Adapter for different operating systems.
We use the mutex-traits crate to provide mutex functionality.
You need to select an appropriate mutex implementation based on your needs.
And you can implement your own mutex by implementing the RawMutex trait from the mutex-traits crate.
use os_trait::{prelude::*, FakeOs, StdOs};
fn os_interface<OS: OsInterface>() {
let mutex = OS::mutex(2);
let mut guard = mutex.try_lock().unwrap();
assert_eq!(*guard, 2);
OS::yield_thread();
}
fn select_os() {
os_interface::<FakeOs>();
os_interface::<StdOs>();
}Required Associated Types§
type RawMutex: ConstInit + RawMutex
type NotifyBuilder: NotifyBuilder
type Timeout: TimeoutNs
Required Methods§
fn yield_thread()
fn delay() -> impl DelayNs
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
Source§impl OsInterface for FakeOs
impl OsInterface for FakeOs
type RawMutex = FakeRawMutex
type NotifyBuilder = FakeNotifier
type Timeout = TickTimeoutNs<FakeInstant>
Source§impl OsInterface for StdOs
Available on crate feature std only.
impl OsInterface for StdOs
Available on crate feature
std only.