Skip to main content

kithara_platform/
lib.rs

1//! Platform-aware primitives for native and wasm32 targets.
2//!
3//! # Synchronization
4//!
5//! Re-exports [`sync`] primitives (`Mutex`, `Condvar`, `RwLock`, `mpsc`)
6//! backed by [`parking_lot`] / `std` on native and [`wasm_safe_thread`] on WASM.
7//!
8//! # Async tasks
9//!
10//! [`tokio::task`] module: [`tokio::task::spawn`],
11//! [`tokio::task::spawn_blocking`], [`tokio::task::yield_now`].
12//!
13//! # Conditional trait bounds
14//!
15//! [`MaybeSend`] and [`MaybeSync`] are conditional trait bounds:
16//! on native they equal `Send`/`Sync`, on wasm32 they are blanket-implemented
17//! for all types. Use in trait bounds to avoid duplicating trait definitions
18//! with `#[cfg]` gates.
19//!
20//! # Async utilities
21//!
22//! [`time::sleep`] delegates to `tokio::time::sleep` on native and to
23//! `setTimeout` on wasm32.
24
25mod cancel_group;
26#[cfg(not(target_arch = "wasm32"))]
27mod env;
28mod maybe_send;
29pub mod sync;
30pub mod thread;
31pub mod time;
32pub mod tokio;
33
34pub use cancel_group::CancelGroup;
35#[cfg(not(target_arch = "wasm32"))]
36pub use env::env_mutation_lock;
37pub use maybe_send::{BoxFuture, MaybeSend, MaybeSendFuture, MaybeSync, WasmSend};
38pub use sync::{
39    Condvar, Mutex, MutexGuard, NotAvailable, RwLock, RwLockReadGuard, RwLockWriteGuard,
40};
41pub use thread::{
42    Duration, JoinHandle, Thread, ThreadId, current, park, park_timeout, sleep, spawn,
43};