b63cf8c9eb
- 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
29 lines
812 B
Rust
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);
|