Installation
Install the dexcost Rust SDK with cargo add, including optional Cargo features and a verification snippet.
cargo add dexcostOr add the dependency directly to your Cargo.toml:
[dependencies]
dexcost = "0.3"
tokio = { version = "1", features = ["full"] }tokio with the full feature set is required because the SDK is async and built on the Tokio runtime.
Optional extras
The SDK ships several optional Cargo features. Each is disabled by default — enable only the ones you need to keep your build lean.
| Feature | What it enables | How to enable |
|---|---|---|
reqwest-middleware | Integrates with the reqwest-middleware crate so that HTTP requests made through a reqwest middleware stack are tracked automatically | dexcost = { version = "0.3", features = ["reqwest-middleware"] } |
axum-middleware | Provides dexcost::middleware::axum::dexcost_middleware, a Tower-compatible layer for Axum routers that records per-request HTTP costs | dexcost = { version = "0.3", features = ["axum-middleware"] } |
tower-middleware | Enables Tower and tower-http integration for middleware stacks that are not Axum-specific | dexcost = { version = "0.3", features = ["tower-middleware"] } |
actix-middleware | Provides middleware for Actix Web 4 services | dexcost = { version = "0.3", features = ["actix-middleware"] } |
gpu | Enables real NVML device readout for GPU cost capture via nvml-wrapper; without it the GPU wrappers compile but record no measurement | dexcost = { version = "0.3", features = ["gpu"] } |
streaming | Enables streaming response support via async-stream | dexcost = { version = "0.3", features = ["streaming"] } |
tracing-bridge | Bridges dexcost events into the tracing ecosystem, emitting structured spans and events that any tracing-subscriber can consume | dexcost = { version = "0.3", features = ["tracing-bridge"] } |
To enable multiple features at once, list them in the features array:
[dependencies]
dexcost = { version = "0.3", features = ["axum-middleware", "streaming"] }Requirements
Async Rust with the Tokio runtime; the crate is edition 2021 and declares no minimum Rust version, so a recent stable toolchain is recommended. The SQLite event buffer is bundled via rusqlite with the bundled feature — no separate SQLite installation is required.
Verify your install
After running cargo add dexcost, confirm the crate resolves and the SDK version constant is accessible:
fn main() {
println!("{}", dexcost::VERSION);
}This prints the installed SDK version (for example, 0.3.1). If the build fails, run cargo check and verify that dexcost appears in your Cargo.lock.