tellus
Getting started

Hello, tellus

Create an actor system with a single actor that handles one message and stops.

Create a new binary crate and add tellus together with Tokio and anyhow:

cargo add anyhow
cargo add tokio --features macros,rt-multi-thread
cargo add tellus

Replace src/main.rs with this program:

use anyhow::Context;
use std::convert::Infallible;
use tellus::{Actor, ActorContext, ActorSystem, Control, Incoming};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let system = ActorSystem::new(Greeter);

    system.root().tell(Greet("Tellus".to_string()));

    system
        .terminated()
        .await
        .context("awaiting actor system termination")
}

struct Greeter;

impl Actor for Greeter {
    type Message = Greet;
    type State = ();
    type Error = Infallible;

    fn init(&self, _: &ActorContext<Self::Message>) -> Result<Self::State, Self::Error> {
        Ok(())
    }

    fn receive(
        &self,
        _: &ActorContext<Self::Message>,
        incoming: Incoming<Self::Message>,
        _: Self::State,
    ) -> Result<Control<Self::State>, Self::Error> {
        if let Incoming::Message(Greet(name)) = incoming {
            println!("Hello, {name}!");
        }
        Ok(Control::Stop)
    }
}

struct Greet(String);

Run it with cargo run and it prints Hello, Tellus!.