OsInterface

Trait OsInterface 

Source
pub trait OsInterface:
    Send
    + Sync
    + 'static {
    type RawMutex: ConstInit + RawMutex;
    type Notifier: Notifier;
    type NotifyWaiter: NotifyWaiter;
    type Timeout: TimeoutNs<TimeoutState = Self::TimeoutState>;
    type TimeoutState: TimeoutState;
    type Delay: DelayNs;

    const O: Self;

    // Required methods
    fn yield_thread();
    fn timeout() -> Self::Timeout;
    fn delay() -> Self::Delay;
    fn notify() -> (Self::Notifier, Self::NotifyWaiter);

    // Provided methods
    fn yield_task() { ... }
    fn mutex<T>(d: T) -> BlockingMutex<Self::RawMutex, T> { ... }
}
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 Constants§

Source

const O: Self

It’s used to avoid writing foo::<OS, _, _, _>(...)

Required Associated Types§

Required Methods§

Source

fn yield_thread()

Source

fn timeout() -> Self::Timeout

Source

fn delay() -> Self::Delay

Source

fn notify() -> (Self::Notifier, Self::NotifyWaiter)

Provided Methods§

Source

fn yield_task()

Source

fn mutex<T>(d: T) -> BlockingMutex<Self::RawMutex, T>

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§