Skip to main content

Platform

Trait Platform 

Source
pub trait Platform: Toolkit {
    const TARGET: &'static str;
    const TOOLKIT: &'static str;

    // Required methods
    fn run(
        self,
        options: WindowOptions,
        ready: Box<dyn FnOnce(Self, Self::Handle, Size)>,
    );
    fn post(f: Box<dyn FnOnce() + Send>);

    // Provided methods
    fn post_delayed(ms: u32, f: Box<dyn FnOnce() + Send>) { ... }
    fn request_frame(_cb: Box<dyn FnOnce(f64) + 'static>) { ... }
    fn locale_hints(&self) -> Vec<String> { ... }
}
Expand description

A platform backend: owns the native main loop and exactly one window in v1 (§8.1).

run sets up the native app + window, installs the reactive scheduler + main poster, then hands (self, root_container, content_size) to ready — which mounts the tree and takes ownership of the backend — and finally runs the native main loop.

Required Associated Constants§

Source

const TARGET: &'static str

e.g. "macos-appkit" — the process-constant target id.

Source

const TOOLKIT: &'static str

The toolkit half of the target, e.g. "appkit".

Required Methods§

Source

fn run( self, options: WindowOptions, ready: Box<dyn FnOnce(Self, Self::Handle, Size)>, )

Source

fn post(f: Box<dyn FnOnce() + Send>)

Post a closure onto the native main loop. Callable from ANY thread; this is the single door the reactive scheduler and Setter deliveries ride (§3.3).

Provided Methods§

Source

fn post_delayed(ms: u32, f: Box<dyn FnOnce() + Send>)

Post f onto the native main loop after (at least) ms milliseconds — the timer door behind day::sleep (docs/async.md). The default spawns a helper thread that sleeps and rides Platform::post home, which is correct on every threaded platform with zero backend code; a single-threaded host (web) overrides it with the platform’s own timer.

Source

fn request_frame(_cb: Box<dyn FnOnce(f64) + 'static>)

Request a single main-thread callback aligned to the next display refresh (vsync), carrying the frame timestamp in seconds. The day-core animation driver re-arms it each tick while animations / game frame-clocks are live and stops requesting when none remain (no idle wakeups → battery). Main-thread only. A backend without a display link may approximate with a ~16 ms timer. Defaulted no-op: the canvas/self-driven animation path is inert until a backend provides it (native-widget animation via AnimSpec is unaffected). (§8.4)

Source

fn locale_hints(&self) -> Vec<String>

Ordered OS locale preference list (BCP-47), for fluent-langneg (§12.2).

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§

Day API ↩ Guides· daybrite.dev