nautilus_common/actor/mod.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2025 Nautech Systems Pty Ltd. All rights reserved.
3// https://nautechsystems.io
4//
5// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6// You may not use this file except in compliance with the License.
7// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16use std::any::Any;
17
18use ustr::Ustr;
19
20pub mod data_actor;
21#[cfg(feature = "indicators")]
22pub(crate) mod indicators;
23pub mod registry;
24
25#[cfg(test)]
26mod tests;
27
28// Re-exports
29pub use data_actor::{DataActor, DataActorCore};
30
31pub trait Actor: Any {
32 /// The unique identifier for the actor.
33 fn id(&self) -> Ustr;
34 /// Handles the `msg`.
35 fn handle(&mut self, msg: &dyn Any);
36 /// Returns a reference to `self` as `Any`, for downcasting support.
37 fn as_any(&self) -> &dyn Any;
38 /// Returns a mutable reference to `self` as `Any`, for downcasting support.
39 ///
40 /// Default implementation simply coerces `&mut Self` to `&mut dyn Any`.
41 ///
42 /// # Note
43 ///
44 /// This method is not object-safe and thus only available on sized `Self`.
45 fn as_any_mut(&mut self) -> &mut dyn Any
46 where
47 Self: Sized,
48 {
49 self
50 }
51}