Skip to main content

rill_handler_api/
lib.rs

1//! Versioned WIT ABI and guest SDK for Rill runtime handlers.
2//!
3//! This crate ships the canonical WIT world definition
4//! ([`wit/rill-handler.wit`](https://github.com/hello-yunshu/rill-ml/tree/main/crates/rill-handler-api/wit/rill-handler.wit))
5//! that every Rill handler must export.
6//!
7//! Handler authors compile a Rust crate to `wasm32-wasip1` using
8//! [`wit-bindgen`](https://crates.io/crates/wit-bindgen) to generate guest
9//! bindings from the WIT file, then wrap the core module into a Component
10//! Model component with `wasm-tools component new`.
11//!
12//! This crate intentionally has **no dependencies** so that it can be consumed
13//! as a build-time WIT source without pulling in any runtime code. The
14//! constants below mirror the WIT declarations and are used by both the host
15//! and guest for compile-time version checks.
16
17/// Handler ABI version. Independent from the host IPC API version and the model
18/// pack format version. Increment only on a breaking WIT change.
19pub const HANDLER_API_VERSION: u32 = 1;
20
21/// WIT package name as declared in `rill-handler.wit`.
22pub const WIT_PACKAGE: &str = "rill:handler";
23
24/// WIT package version as declared in `rill-handler.wit`.
25pub const WIT_VERSION: &str = "1.0.0";
26
27/// WIT world name as declared in `rill-handler.wit`.
28pub const WIT_WORLD: &str = "invoke-handler";
29
30/// Maximum number of capabilities a handler may declare.
31pub const MAX_CAPABILITIES: usize = 32;
32
33/// Maximum length of a capability string.
34pub const MAX_CAPABILITY_LEN: usize = 96;
35
36/// Maximum length of a handler id.
37pub const MAX_HANDLER_ID_LEN: usize = 96;
38
39/// Maximum length of a handler version string.
40pub const MAX_HANDLER_VERSION_LEN: usize = 48;
41
42#[cfg(test)]
43mod tests {
44    use super::*;
45
46    #[test]
47    fn constants_are_stable() {
48        assert_eq!(HANDLER_API_VERSION, 1);
49        assert_eq!(WIT_PACKAGE, "rill:handler");
50        assert_eq!(WIT_VERSION, "1.0.0");
51        assert_eq!(WIT_WORLD, "invoke-handler");
52    }
53}