Quick Start

Build your first Cineyma application in 5 minutes.

Create a New Project

Start by creating a new Rust project:

Add Cineyma and Tokio to your dependencies:

Cargo.toml
toml
1
2
3
4
5
6
7
8

Step 1: Define Your Actor

An actor is a struct that implements the Actor trait. Let's create a simple counter:

src/main.rs
rust
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

Step 2: Define Messages

Messages are how you communicate with actors. Each message has a typed result:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

Step 3: Implement Handlers

Handlers define how your actor responds to each message type:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

Step 4: Spawn and Use Your Actor

Now let's create the actor system, spawn our actor, and send messages:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

Complete Code

Here's the complete example you can copy and run:

src/main.rs
rust
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

Run with cargo run:

Key Concepts

Actor

A struct that holds state and processes messages sequentially. Only one message is processed at a time, eliminating data races.

Message

A typed value sent to an actor. Each message type has an associated Result type for responses.

Handler

Defines how an actor processes a specific message type. The handler has exclusive access to the actor's state.

Address (Addr)

A handle to send messages to an actor. Addresses are cheap to clone and can be shared across tasks.

Context

Provides the actor with access to its own address, the ability to spawn children, schedule timers, and more.

Message Sending Patterns

Cineyma provides three ways to send messages:

1
2
3
4
5
6
7
8
9

Next Steps

You've built your first Cineyma application! Continue learning: