cranpose_core/platform.rs
1//! Platform abstraction traits for Compose runtime services.
2//!
3//! These traits allow Compose to delegate scheduling and clock
4//! responsibilities to the host platform, enabling integration with
5//! different environments without depending directly on `std` APIs.
6
7/// Schedules work for the Compose runtime.
8///
9/// Implementations are responsible for triggering frame processing and
10/// executing background tasks on behalf of Compose.
11#[cfg(not(target_arch = "wasm32"))]
12pub trait RuntimeScheduler: Send + Sync {
13 /// Request that the host schedule a new frame.
14 fn schedule_frame(&self);
15}
16
17/// Schedules work for the Compose runtime on single-threaded wasm hosts.
18#[cfg(target_arch = "wasm32")]
19pub trait RuntimeScheduler {
20 /// Request that the host schedule a new frame.
21 fn schedule_frame(&self);
22}
23
24/// Provides timing information for the runtime.
25pub trait Clock: Send + Sync {
26 /// Instant type produced by this clock implementation.
27 type Instant: Copy + Send + Sync;
28
29 /// Returns the current instant.
30 fn now(&self) -> Self::Instant;
31
32 /// Returns the number of milliseconds elapsed since `since`.
33 fn elapsed_millis(&self, since: Self::Instant) -> u64;
34}