ic-rig 0.2.0

A lean, modular library for building LLM applications. Bring your own HTTP client.
Documentation
//! WASM compatibility shims.
//!
//! On native targets, async code requires `Send` bounds to work across threads.
//! On WASM (single-threaded), those bounds are unnecessary and will prevent
//! compilation. These traits alias to the appropriate bound per target.
//!
//! Always use [`WasmCompatSend`] and [`WasmCompatSync`] instead of raw `Send`/`Sync`
//! in trait bounds throughout this crate.

use std::{future::Future, pin::Pin};

// ── WasmCompatSend ────────────────────────────────────────────────────────────

#[cfg(not(target_family = "wasm"))]
pub trait WasmCompatSend: Send {}
#[cfg(not(target_family = "wasm"))]
impl<T: Send> WasmCompatSend for T {}

#[cfg(target_family = "wasm")]
pub trait WasmCompatSend {}
#[cfg(target_family = "wasm")]
impl<T> WasmCompatSend for T {}

// ── WasmCompatSync ────────────────────────────────────────────────────────────

#[cfg(not(target_family = "wasm"))]
pub trait WasmCompatSync: Sync {}
#[cfg(not(target_family = "wasm"))]
impl<T: Sync> WasmCompatSync for T {}

#[cfg(target_family = "wasm")]
pub trait WasmCompatSync {}
#[cfg(target_family = "wasm")]
impl<T> WasmCompatSync for T {}

// ── BoxFuture ─────────────────────────────────────────────────────────────────

/// A heap-allocated, type-erased future.
///
/// Intentionally non-`Send` on all targets. This keeps the library usable on
/// single-threaded runtimes (ICP, WASM) without pulling in extra constraints.
/// If you need a `Send` future on native, wrap at the call site.
pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a>>;