A worker needs settings and access to the resources it processes. You might want a misspelled setting to fail the build, and a file-reading component to stay inside the directory you gave it.
Hew 0.6.1 adds typed data embedded at compile time and confinement around supplied services. Generic closures help reusable code work across types, while deeper machine hierarchies organize the states of a running service. Let’s start with a worker’s settings, then give an actor a directory to read.
Check settings when you build
Save this as service.toml:
name = "order-worker"
workers = 4
enabled = trueThen save config.hew beside it:
type Config {
name: string;
workers: i64;
enabled: bool;
}
const CONFIG: Config = embed!("service.toml");
fn main() {
let report = |<T: Display> label: string, value: T| {
println(f"{label}: {value}");
};
report("service", CONFIG.name);
report("workers", CONFIG.workers);
report("enabled", CONFIG.enabled);
}Run hew run config.hew:
service: order-worker
workers: 4
enabled: trueembed! reads the file during compilation and checks its data against Config. The executable contains ordinary typed values, so it can start without the TOML file. Changing these settings requires rebuilding. JSON and YAML inputs work through the same type and serialization rules.
The report closure has a type parameter inside its opening pipe. Its Display bound permits formatting each value; the three calls infer string, i64 and bool. You can also store or return a generic closure with a type such as fn<T: Display>(string, T).
Supply a directory at construction
Now create a small input:
mkdir -p inputs
printf 'order\n' > inputs/order.txtSave this as files.hew:
import std.fs;
#[confined]
actor FileSizes {
let input: fs.ReadDir;
receive fn count(path: string) -> Result<i64, fs.IoError> {
match input.read(path) {
.Ok(data) => .Ok(data.len()),
.Err(error) => .Err(error),
}
}
}
fn main() {
let sizes = spawn FileSizes {
input: fs.open_read_dir("inputs").expect("open input directory"),
};
let count = sizes.count("order.txt").expect("actor reply").expect("read file");
println(count);
stop(sizes);
stopped(sizes);
}hew run files.hew prints 6. The handler reads the whole file and returns its byte length. Its result describes a filesystem error; the actor call also has its own reply result, which is why the example handles both.
main opens a read-only directory resource and supplies it when constructing the actor. Callers then pass a relative filename. Absolute paths, parent escapes and symlinks that escape the root are refused. A WriteDir grants writing, and subdir narrows either resource to a child directory. These filesystem resources execute natively.
The #[confined] declaration prevents the component from acquiring broader ambient authority, including through helpers and callbacks. The actor can use its supplied directory; hidden filesystem or process acquisition fails checking. You can build domain interfaces around these services and supply an in-memory implementation in the browser VM.
The final two calls request actor shutdown and wait for it to finish, including closing its owned directory resource.
Build on the same model
Machines can now nest composite states more deeply. Named transitions retain shared ancestors; a computed _ destination exits the full active branch, runs its body once and enters the branch it returns. This distinction matters when entry and exit hooks own resources.
Actor calls inherit the earliest scope or incoming request deadline. Expired queued calls never start; cancellation and caller expiry stay responsive during stalled transport. Required cleanup can finish after that request budget expires. A remote call that has already started may have changed state before its caller times out, so callers must account for that possibility.
Native execution also improves synchronous callables, coroutine lowering and owned payload transfer. A checker fix addresses excessively long compile times in large programs with ordinary records and enums. The browser VM now compares strings in the same UTF-8 order as native Hew.
Upgrade and try the examples
Install the release and run the two programs above:
curl -fsSL https://hew.sh/install | bash -s -- --version 0.6.1Upgrade communicating nodes together: this release moves the wire protocol from v2 to v4 and explicitly rejects earlier versions. Rebuild native integrations with the matching compiler, runtime and standard library. Review computed machine transitions if their hooks depend on retaining a common ancestor.
Hew 0.6.1 also updates rustls from 0.23.45 to 0.23.46 to address upstream security advisories. The release notes include the advisories and remaining upgrade details; the language specification covers the new syntax and behaviour.