Crates.io | acton-reactive |
lib.rs | acton-reactive |
version | |
source | src |
created_at | 2024-10-03 23:56:27.567518 |
updated_at | 2024-12-02 03:53:00.981529 |
description | Acton Reactive is the main crate of the Acton framework, designed for building reactive, event-driven, and asynchronous systems. It provides intuitive abstractions to make working with distributed agents seamless and efficient. |
homepage | https://github.com/Govcraft/acton-reactive |
repository | https://github.com/Govcraft/acton-reactive |
max_upload_size | |
id | 1395821 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Welcome to Acton! This framework makes it easy to build fast, responsive Rust applications using a simple message-passing system. Think of Acton as a team of helpful workers (I call them "agents") who can pass messages to each other and handle different tasks independently. The name "Acton" comes from what these agents do - they "act on" the messages you send them!
Easy-to-Use Agents: Agents are like independent workers in your application. Each one can handle its own tasks and keep track of its own information, making it natural to write programs that do many things at once.
Simple Message Passing: Agents communicate by sending messages to each other, just like people passing notes. Thanks to Rust's async/await features, these messages get delivered efficiently without blocking other work.
Flexible and Adaptable: You can easily customize Acton to fit your needs. Whether you're building a small application or a large system, Acton grows with you.
Safe and Reliable: Rust's type system helps ensure that messages get delivered to the right places. This means fewer bugs and more reliable applications.
Built-in Monitoring: Acton comes with tools to help you see what's happening inside your application, making it easier to find and fix problems.
Add Acton to your project by putting this in your Cargo.toml
:
[dependencies]
acton-reactive = "3.0.0-beta.3"
Let's walk through a simple example to see how Acton works!
First, let's import what I need and create a simple agent:
use acton_reactive::prelude::*;
// Create an agent that can keep track of a number
#[derive(Debug, Default)]
struct CounterAgent {
count: usize,
}
Messages are how agents communicate. Let's create some simple ones:
// The traditional way:
#[derive(Debug, Clone)]
struct PingMsg;
// Or use the helpful shortcut:
#[acton_message]
struct PongMsg;
#[acton_message]
struct GoodbyeMsg;
Here's how to set up your application and create an agent:
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Start up Acton
let mut app = ActonApp::launch();
// Create the counter agent
let mut counter = app.new_agent::<CounterAgent>().await;
Now let's make the agent do something when it receives messages:
counter
// When someone sends a Ping...
.act_on::<PingMsg>(|agent, context| {
println!("Got a ping! Adding to count...");
agent.model.count += 1;
// Send a Pong back
let envelope = context.reply_envelope();
Box::pin(async move {
envelope.send(PongMsg).await;
})
})
// When someone sends a Pong...
.act_on::<PongMsg>(|agent, _envelope| {
println!("Got a pong! Adding to count...");
agent.model.count += 1;
// Send a Goodbye to ourselves
let handle = agent.handle().clone();
AgentReply::from_async(async move {
handle.send(GoodbyeMsg).await;
})
})
// When someone says Goodbye...
.act_on::<GoodbyeMsg>(|_agent, _envelope| {
println!("Time to say goodbye!");
AgentReply::immediate()
});
// Start the agent
let counter = counter.start().await;
// Send it a message
counter.send(PingMsg).await;
// Shut everything down nicely
app.shutdown_all().await?;
Ok(())
}
Want to see more? Check out the example projects:
basic: A simple example like the one above
lifecycles: See how agents start up and shut down
broadcast: Learn how to send messages to multiple agents
fruit_market: A fun example showing how to build a more complex system )
While Acton is similar to traditional actor frameworks (like Akka or Erlang), I use the term "agent" to keep things simple and friendly. An agent is just something that can receive messages and act on them - no complicated theory required!
An agent in Acton is like a helpful worker that can:
Think of agents as team members who can work on their own tasks while communicating with each other when needed.
Not at all! While Acton is powerful enough for complex applications, I've designed it to be easy to understand and use. It takes advantage of Rust's modern features (like async/await) to keep things simple while still being fast and reliable.
I'd love your help making Acton even better! Feel free to:
You can use Acton under either the MIT or Apache-2.0 license - whichever works
better for you. Check out the LICENSE-MIT
and LICENSE-APACHE
files for the
details.
Find me on Bluesky