Skip to main content

Platform

Trait Platform 

Source
pub trait Platform: Toolkit {
    const TARGET: &'static str;
    const TOOLKIT: &'static str;
    const RUN_ENDS_APP: bool = true;

    // 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 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

The process-constant target id, e.g. "macos-appkit".

Source

const TOOLKIT: &'static str

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

Provided Associated Constants§

Source

const RUN_ENDS_APP: bool = true

Whether Platform::run returning means the app is over. True for a backend that drives the native loop itself until the app quits (GTK, Qt, XAML; AppKit’s never returns). False where the host owns the loop and run hands back at once, with the app still to come (ArkUI’s ability, Android’s activity, the web page, the mock’s test): their DidExit is the host’s last callback, not the return (docs/lifecycle.md).

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). Every shipped backend overrides it with the loop’s own timer (dispatch_after, Handler.postDelayed, g_timeout_add, QTimer::singleShot, SetTimer, setTimeout), so a sleep costs no thread. The default is the fallback for a backend without one: a helper thread that sleeps the whole delay and rides Platform::post home. It is correct, but a thread per sleep adds up under a ticking loop, so the first use says so once in the log.

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".

Implementors§