Files
wasmeld/components/counter/src/lib.rs
T
Maofeng b63cf8c9eb feat(runtime): add resident Wasmtime actor runtime
- define versioned service and clock WIT contracts\n- enforce import allowlists, fuel, epoch, memory, I/O, and mailbox limits\n- keep one Store and Component Instance resident per serial Actor\n- add echo, counter, fault, spin, and capability probe components\n- cover lifecycle, concurrency, sandbox, and fault recovery behavior
2026-07-27 04:59:33 +08:00

29 lines
812 B
Rust

use core::sync::atomic::{AtomicU64, Ordering};
mod bindings {
wit_bindgen::generate!({
path: "wit",
world: "counter-component",
});
}
static COUNTER: AtomicU64 = AtomicU64::new(0);
struct Counter;
impl bindings::Guest for Counter {
fn init(_config: Vec<u8>) -> Result<(), bindings::ServiceError> {
// Calls are serialized by the host Actor, so this component intentionally
// uses one mutable global to make resident memory observable in tests.
COUNTER.store(0, Ordering::Relaxed);
Ok(())
}
fn invoke(_input: Vec<u8>) -> Result<Vec<u8>, bindings::ServiceError> {
let next = COUNTER.fetch_add(1, Ordering::Relaxed).wrapping_add(1);
Ok(next.to_le_bytes().to_vec())
}
}
bindings::export!(Counter with_types_in bindings);