libdd-capabilities
Portable capability traits for cross-platform libdatadog.
Overview
libdd-capabilities defines abstract traits that decouple core libdatadog crates from platform-specific I/O. Core crates are generic over a capability parameter C that implements these traits, allowing native and wasm targets to provide different backends without changing shared logic.
This crate has zero platform dependencies: it compiles on any target including wasm32-unknown-unknown.
Traits
HttpClientTrait: Async HTTP request/response usinghttp::Request<Bytes>/http::Response<Bytes>.MaybeSend: ConditionalSendbound: equivalent toSendon native, auto-implemented for all types on wasm. This bridges the gap between tokio's multi-threaded runtime (requiresSendfutures) and wasm's single-threaded model (where JS interop types are!Send).
Architecture
Three-layer design:
- Trait definitions (this crate): Pure traits, no platform deps.
- Core crates (
libdd-trace-utils,libdd-data-pipeline): Generic overC: HttpClientTrait. Depend only on this crate for trait bounds. - Leaf crates (FFI, wasm bindings): Pin a concrete type,
NativeCapabilitiesfromlibdd-capabilities-implon native,WasmCapabilitiesfrom the Node.js binding crate on wasm.
Usage
use ;
async
Critical rule: never use + Send directly in trait bounds for async functions in wasm-compatible code. Always use + MaybeSend instead.