Skip to main content

nautilus_common/actor/
mod.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 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
16//! Actor system for event-driven message processing.
17//!
18//! This module provides the actor framework used throughout NautilusTrader for handling
19//! data processing, event management, and asynchronous message handling. Actors are
20//! lightweight components that process messages in isolation.
21
22#![allow(unsafe_code)]
23
24use std::{any::Any, fmt::Debug};
25
26use ustr::Ustr;
27
28pub mod data_actor;
29pub mod indicators;
30pub mod registry;
31
32#[cfg(test)]
33pub(crate) mod tests;
34
35// Re-exports
36pub use data_actor::{DataActor, DataActorConfig, DataActorCore, DataActorNative};
37
38pub use crate::component::Component;
39
40pub trait Actor: Any + Debug {
41    /// The unique identifier for the actor.
42    fn id(&self) -> Ustr;
43    /// Handles the `msg`.
44    fn handle(&mut self, msg: &dyn Any);
45    /// Returns a reference to `self` as `Any`, for downcasting support.
46    fn as_any(&self) -> &dyn Any;
47    /// Returns a mutable reference to `self` as `Any`, for downcasting support.
48    ///
49    /// Default implementation simply coerces `&mut Self` to `&mut dyn Any`.
50    ///
51    /// # Note
52    ///
53    /// This method is not object-safe and thus only available on sized `Self`.
54    fn as_any_mut(&mut self) -> &mut dyn Any
55    where
56        Self: Sized,
57    {
58        self
59    }
60}