~ knotless Search/
↑↓ move↵ open⇧↵ all results

johnandersen777.bsky.social/atlibs

0
0
main
42 lines · 1.5 KB Raw History
# Use a module in Rust

`atlibs-host` is the host behind the CLI, a crate taken by git at a pinned rev. `examples/rust-host` is
a whole program; copy the directory to start your own.

`examples/rust-host/Cargo.toml`

```toml
[dependencies]
atlibs-host = { git = "https://knotless.dev/johnandersen777.bsky.social/atlibs", rev = "7df7c6a" }
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls"] }
serde_json = "1"
tokio = { version = "1", features = ["full"] }
```

`examples/rust-host/src/main.rs`

```rust
    let module = Module::from_manifest(read("wasm")?, &spec)?;

    let ctx = Ctx { runner: Arc::new(Bound { wasm: Wasm::new(5000), bytes: module.bytes.clone(), sha256: None }), ledger: None, now: None };
    // signed out: public reads only (a Session here acts as an account)
    let fetch: Arc<dyn Fetch> = Arc::new(reqwest::Client::new());
    let call = Arc::new(HostCall { fetch, session: None, attest: None });
    let input = json!({ "did": did, "collection": "com.fedfork.exec.wasm.module" });
    let ran = run_module(&ctx, &module, "count", input.as_object().unwrap(), call, Options::default()).await;
```

```bash run=install
cd examples/rust-host
atlibs add bobvmbuilder.bsky.social/hello
cargo run --release -- modules/hello did:plc:ocnuqjlzgohypj3zoznermms
```

```output
{"collection":"com.fedfork.exec.wasm.module","records":…}
```

The first build takes a few minutes (wasmtime). Sessions, compositions, client metadata:
[Rust servers](../server/rust.md).

Previous: [CLI](cli.md) | Next: [Write a module](write.md)