Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
A

actix

> 编程语言
Open source

Actor framework for Rust.

9.2K stars0 likes3 views
WebsiteGitHub

About

Actor framework for Rust.

Documentation

  • User Guide
  • API Documentation

Features

  • Async and sync actors
  • Actor communication in a local/thread context
  • Uses futures for asynchronous message handling
  • Actor supervision
  • Typed messages (No Any type)
  • Runs on stable Rust 1.88+

Usage

To use actix, add this to your Cargo.toml:

toml
[dependencies]
actix = "0.13"

Initialize Actix

In order to use actix you first need to create a System.

fn main() {
    let system = actix::System::new();

    system.run();
}

Actix uses the Tokio runtime. System::new() creates a new event loop. System.run() starts the Tokio event loop, and will finish once the System actor receives the SystemExit message.

Implementing an Actor

In order to define an actor you need to define a struct and have it implement the Actor trait.

rust
use actix::{Actor, Context, System};

struct MyActor;

impl Actor for MyActor {
    type Context = Context<Self>;

    fn started(&mut self, _ctx: &mut Self::Context) {
        println!("I am alive!");
        System::current().stop(); // <- stop system
    }
}

fn main() {
    let system = System::new();

    let _addr = system.block_on(async { MyActor.start() });

    system.run().unwrap();
}

Spawning a new actor is achieved via the start and create methods of the Actor trait. It provides several different ways of creating actors; for details, check the docs. You can implement the started, stopping and stopped methods of the Actor trait. started gets called when the actor starts and stopping when the actor finishes. Check the API docs for more information on the actor lifecycle.

Handle Messages

An Actor communicates with another Actor by sending messages. In actix all messages are typed. Let's define a simple Sum message with two usize parameters and an actor which will accept this message and return the sum of those two numbers. Here we use the #[actix::main] attribute as an easier way to start our System and drive our main function so we can easily .await for the responses sent back from the Actor.

…

All communications with actors go through an Addr object. You can do_send a message without waiting for a response, or you can send an actor a specific message. The Message trait defines the result type for a message.

Actor State And Subscription For Specific Messages

You may have noticed that the methods of the Actor and Handler traits accept &mut self, so you are welcome to store anything in an actor and mutate it whenever necessary.

Address objects require an actor type, but if we just want to send a specific message to an actor that can handle the message, we can use the Recipient interface. Let's create a new actor that uses Recipient.

…

Chat Example

See this chat example which shows more comprehensive usage in a networking client/server service.

Contributing

All contributions are welcome, if you have a feature request don't hesitate to open an issue!

License

This project is licensed under either of

  • Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
  • MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)

at your option.

Code of Conduct

Contribution to the actix repo is organized under the terms of the Contributor Covenant. The Actix team promises to intervene to uphold that code of conduct.

Issues· 35 open

View all issuesOpen on GitHub
  • #531

    "there is no reactor running" panic when system is quickly dropped

    C-bughelp wantedA-actixUpdated Apr 26, 2026
  • #469

    A macro to generate message handler boilerplate

    Updated Dec 14, 2024
  • #378

    Async/await interop suggestion

    Updated Jul 18, 2024
  • #583

    Fine-tune the Ordering for num_senders

    Updated Mar 2, 2024
  • #332

    Actor doesn't fully stops when `stopping` returns `Running::continue` at least once

    Updated Nov 12, 2022
  • #541

    Conditional inclusion of tokio-net and tokio-signal for targets that do not support them.

    Updated Oct 6, 2022
  • #504

    Allow Actors with a SyncContext to be registered in the SystemRegistry

    help wantedUpdated Aug 23, 2022
  • #515

    Addr::send does not respect Mailbox size

    C-bugA-actixUpdated May 24, 2022
  • #528

    Question: How to wait for an event on actor startup?

    questionUpdated May 24, 2022
  • #520

    Fair handling of async sub-tasks in ContextFut

    C-bughelp wantedUpdated Feb 3, 2022

> Tags

Rustactixactoractor-modelconcurrency

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 29, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言