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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
use crateServiceAssistant;
use Debug;
///
/// Services are id-less actors that can process messages with certain concurrency.
/// The concurrency level can be configured during the "initialize" method with the
/// ServiceConfiguration struct.
///
/// ```rust,no_run
/// use acteur::{Acteur, Service, Serve, ServiceAssistant, ServiceConfiguration};
///
/// #[derive(Debug)]
/// struct EmployeeTaxesCalculator {
/// tax_rate: f32,
/// }
///
/// #[async_trait::async_trait]
/// impl Service for EmployeeTaxesCalculator {
/// async fn initialize(system: &ServiceAssistant<Self>) -> (Self, ServiceConfiguration) {
/// let service = EmployeeTaxesCalculator {
/// tax_rate: 0.21,
/// };
///
/// let service_conf = ServiceConfiguration::default();
///
/// (service, service_conf)
/// }
/// }
///
/// #[derive(Debug)]
/// struct EmployeeSalaryChange(f32);
///
/// #[async_trait::async_trait]
/// impl Serve<EmployeeSalaryChange> for EmployeeTaxesCalculator {
/// type Response = f32;
///
/// async fn handle(&self, message: EmployeeSalaryChange, system: &ServiceAssistant<Self>) -> f32 {
/// self.tax_rate * message.0
/// }
/// }
///
/// fn main() {
/// let sys = Acteur::new();
///
/// let taxes = sys.call_service_sync::<EmployeeTaxesCalculator, _>(EmployeeSalaryChange(55000.0)).unwrap();
///
/// println!("Employee taxes are: {:?}", taxes);
///
/// sys.stop();
///
/// sys.wait_until_stopped();
/// }
/// ```
///
/// Defined the concurrency from the Service.
///
/// In the majority of cases you may want to use "Automatic".
/// Defines the service configuration. For now it only contains the concurrency parameters.
///
/// This struct implements the Default trait. You can call it with `ServiceConfiguration::default()` and
/// it should work well for the most of the cases..