actor_sample/user_actor/mod.rs
1//! # User Actor
2//!
3//! This module implements the User resource actor, managing user entities with CRUD operations.
4//!
5//! ## Overview
6//!
7//! The User actor is the simplest example in the system, demonstrating the basic actor pattern
8//! without dependencies or custom actions. It manages user registration and profile information.
9//!
10//! ## Structure
11//!
12//! - [`entity`] - [`ActorEntity`](actor_framework::ActorEntity) implementation for [`User`]
13//! - [`error`] - [`UserError`] type for type-safe error handling
14//! - [`new()`] - Factory function that creates the actor and client
15//!
16//! ## Usage
17//!
18//! ```rust
19//! use actor_sample::user_actor;
20//! use actor_sample::clients::UserClient;
21//! use actor_sample::model::UserCreate;
22//!
23//! #[tokio::main]
24//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
25//! // Create actor and client
26//! let (actor, generic_client) = user_actor::new();
27//! let client = UserClient::new(generic_client);
28//!
29//! // Start the actor (no dependencies, so context is ())
30//! tokio::spawn(actor.run(()));
31//!
32//! // Use the client
33//! let params = UserCreate {
34//! name: "Alice".to_string(),
35//! email: "alice@example.com".to_string(),
36//! };
37//! let id = client.create_user(params).await?;
38//! Ok(())
39//! }
40//! ```
41//!
42//! ## Key Features
43//!
44//! - **No dependencies**: User actor has no context dependencies (Context = ())
45//! - **Sequential ID generation**: Uses atomic counter for deterministic IDs
46//! - **Type-safe errors**: All operations return `Result<T, UserError>`
47
48pub mod entity;
49pub mod error;
50
51pub use error::*;
52
53use crate::model::User;
54use actor_framework::ResourceActor;
55use actor_framework::ResourceClient;
56
57/// Creates a new User actor and its client.
58pub fn new() -> (ResourceActor<User>, ResourceClient<User>) {
59 ResourceActor::new(10)
60}