11# uActor
2+
23## Overview
3- The fastest and most modular actor system that doesn’t force you to pay for what you don’t need
4+
5+ The fastest and most modular actor system that doesn't force you to pay for what you don't need.
6+
7+ ## Quick Start
8+
9+ Define messages with ` #[derive(Message)] ` , implement handlers with ` #[uactor::actor] ` / ` #[uactor::handler] ` :
10+
11+ ``` rust
12+ #[derive(uactor:: Message )]
13+ struct Increment ;
14+
15+ #[derive(uactor:: Message , Debug )]
16+ struct GetCount (Reply <CountResponse >);
17+
18+ struct CounterActor { count : u32 }
19+
20+ impl Actor for CounterActor {
21+ type Context = Context ;
22+ type RouteMessage = CounterActorMsg ;
23+ type Inject = ();
24+ type State = ();
25+ }
26+
27+ #[uactor:: actor]
28+ impl CounterActor {
29+ #[uactor:: handler]
30+ async fn handle_increment (& mut self , _msg : Increment ) -> HandleResult {
31+ self . count += 1 ;
32+ Ok (())
33+ }
34+
35+ #[uactor:: handler]
36+ async fn handle_get (& self , GetCount (reply ): GetCount ) -> HandleResult {
37+ let _ = reply . send (CountResponse (self . count));
38+ Ok (())
39+ }
40+ }
41+
42+ uactor :: generate_actor_ref! (CounterActor , { Increment , GetCount });
43+ ```
44+
45+ See the full runnable version: [ Example: Macro handlers] ( src/uactor/examples/macro_handlers.rs )
446
547## Examples
48+
649Examples can be found [ here] ( src/uactor/examples ) .
750
8- ### Features
9- 1 . Simplified creation of a tokio actor topic oriented actor
51+ ## Features
52+
53+ 1 . Simplified creation of tokio-based topic-oriented actors
10542 . Minimum boilerplate code
11- 3 . Support different tokio channels including ` watch ` , ` broadcast ` , ` oneshot ` , ` mpsc ` .
12- 4 . Each actor is able to listen up to 30 channels.
13- 5 . Added support of actors with single real channel and routing messages to the defined handler
14- [ Example: Single channel] ( src/uactor/examples/single_channel_actor.rs )
15- 6 . Added tick (actor call each n seconds/millis/etc) support
16- [ Example: Interval] ( src%2Fuactor%2Fexamples%2Finterval .rs )
17- 7 . Implemented Dependency Injection on pre-start stage to solve cross-references problem ("Actor#1" needs a reference to the "Actor#2", and "Actor#2" needs a reference to "Actor#1")
18- [ Example: dependency injection] ( src/uactor/examples/dependency_injection.rs )
55+ 3 . Support for different tokio channels including ` watch ` , ` broadcast ` , ` oneshot ` , ` mpsc `
56+ 4 . Each actor is able to listen up to 30 channels
57+ 5 . Single channel routing with ` generate_actor_ref! `
58+ [ Example: Single channel] ( src/uactor/examples/single_channel_actor.rs )
59+ 6 . Tick support (actor called each n seconds/millis/etc)
60+ [ Example: Interval] ( src/uactor/examples/interval .rs )
61+ 7 . Dependency Injection on pre-start stage to solve cross-references ("Actor#1" needs "Actor#2" and vice versa)
62+ [ Example: Dependency injection] ( src/uactor/examples/dependency_injection.rs )
19638 . Integration with tokio/tracing, including tracing of actor lifecycle, messages, and handlers
20- 9 . Implemented support for actors for which it is necessary to work with multiple message sources (channels) [ Example: Multi channel] ( ./src/uactor/examples/multiple_incoming_channels.rs )
21- 10 . Implemented shared state for actors [ Example: Shared state] ( ./src/uactor/examples/shared_state.rs )
64+ 9 . Multiple message sources (channels) per actor
65+ [ Example: Multi channel] ( src/uactor/examples/multiple_incoming_channels.rs )
66+ 10 . Shared state for actors
67+ [ Example: Shared state] ( src/uactor/examples/shared_state.rs )
68+
69+ ### Derive and macro support
70+
71+ - ** ` #[derive(Message)] ` ** -- implement the ` Message ` trait without boilerplate.
72+ Also available as ` message_impl!(MsgA, MsgB) ` for multiple types at once.
73+
74+ - ** ` #[uactor::actor] ` + ` #[uactor::handler] ` ** -- define message handlers as simple methods
75+ instead of manual ` impl Handler<M> ` for each message type.
76+
77+ Handler parameters:
78+ - First parameter (after optional ` &mut self ` / ` &self ` ) -- the message; its type determines ` Handler<Type> `
79+ - ` ctx ` -- maps to ` &mut Self::Context `
80+ - ` state ` -- maps to ` &Self::State `
81+ - Any other parameter -- accessed as a field from the ` Inject ` struct by name
82+
83+ - ** ` generate_actor_ref! ` with aliased variants** -- map primitive or external types
84+ to named enum variants:
85+ ``` rust
86+ uactor :: generate_actor_ref! (MyActor , { PingMsg , NextId : i32 , Label : String });
87+ // Generates: enum MyActorMsg { PingMsg(PingMsg), NextId(i32), Label(String) }
88+ ```
89+
90+ [ Example: Macro handlers] ( src/uactor/examples/macro_handlers.rs )
2291
2392### Actor lifecycle
93+
2494![ Lifecycle.png] ( docs/assets/Lifecycle.png )
2595
26- ### Other projects:
96+ ### Other projects
97+
27981 . Actix
28992 . Ractor
291003 . Tokactor
@@ -37,4 +108,4 @@ This project is licensed under the [MIT license](LICENSE).
37108
38109Unless you explicitly state otherwise, any contribution intentionally submitted
39110for inclusion in uActor by you, shall be licensed as MIT, without any additional
40- terms or conditions.
111+ terms or conditions.
0 commit comments