archy
A lightweight async application framework for Rust. Inspired by Bevy/Axum, built for async.
Installation
[]
= "0.3"
= { = "1", = ["full"] }
Quick Start
use ;
async
async
Services
Services are actor-like components that process messages. The #[derive(Service)] and #[service] macros generate message types and client methods:
use *;
Register services and call them using Client<S>:
app.;
async
Service calls return Result<T, ServiceError>. Use .timeout() to add timeouts:
use Duration;
let result = greeter.greet.timeout.await;
Systems
Systems are async functions that run at specific lifecycle phases:
Schedule::First- Before services startSchedule::Startup- After services startSchedule::Run- Background tasks until shutdownSchedule::Fixed(Duration)- Periodic interval tasksSchedule::Shutdown- When shutdown triggeredSchedule::Last- After everything stops
use Duration;
app.add_system;
app.add_system;
app.add_system;
Systems can return Result<(), E> to trigger restart policies on error.
Resources
Shared state injected into services and systems:
app.add_resource;
async
// Services use the same extractors
Events
Pub/sub broadcasting with Emit<E> and Sub<E>:
app.;
async
async
Configuration
Services, systems, and events can be configured:
// Service config
app.
.workers
.capacity
.concurrent // or .sequential()
.restart;
// System config
app.add_system
.workers
.restart;
// Event config
app.
.capacity;
// Shutdown timeout
app.shutdown.timeout;
Set defaults before registration:
app.service_defaults.workers.capacity;
app.system_defaults.restart;
app.event_defaults.capacity;
Restart Policies
Control restart behavior for services and systems:
Never // No restart (default)
Always // Always restart on panic/error
Attempts
attempts // Helper with default reset window
Services restart on panic. Systems restart on panic or Err return.
Batch Registration
Register multiple items using tuples:
app.add_resources;
app.;
app.;
app.add_systems;
Modules
Organize registration with the Module trait:
app.add_module;
Error Handling
Service calls return Result<T, ServiceError>:
Flatten nested results with .flatten_into():
// When a service method returns Result<T, BusinessError>
let result: = users.create.flatten_into.await;
// Requires: AppError: From<ServiceError> + From<BusinessError>
License
Licensed under either of Apache License, Version 2.0 or MIT license.