nautilus_core/lib.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//! Core foundational types and utilities for [NautilusTrader](https://nautilustrader.io).
17//!
18//! The `nautilus-core` crate is designed to be lightweight, efficient, and to provide zero-cost abstractions
19//! wherever possible. It supplies the essential building blocks used across the NautilusTrader
20//! ecosystem, including:
21//!
22//! - Time handling and atomic clock functionality.
23//! - UUID generation and management.
24//! - Mathematical functions and interpolation utilities.
25//! - Correctness validation functions.
26//! - Serialization traits and helpers.
27//! - Cross-platform environment utilities.
28//! - Abstractions over common collections.
29//!
30//! # NautilusTrader
31//!
32//! [NautilusTrader](https://nautilustrader.io) is an open-source, production-grade, Rust-native
33//! engine for multi-asset, multi-venue trading systems.
34//!
35//! The system spans research, deterministic simulation, and live execution within a single
36//! event-driven architecture, providing research-to-live semantic parity.
37//!
38//! # Feature Flags
39//!
40//! This crate provides feature flags to control source code inclusion during compilation,
41//! depending on the intended use case, i.e. whether to provide Python bindings
42//! for the [nautilus_trader](https://pypi.org/project/nautilus_trader) Python package,
43//! or as part of a Rust only build.
44//!
45//! - `ffi`: Enables the C foreign function interface (FFI) from [cbindgen](https://github.com/mozilla/cbindgen).
46//! - `python`: Enables Python bindings from [PyO3](https://pyo3.rs).
47//! - `extension-module`: Builds the crate as a Python extension module.
48
49#![warn(rustc::all)]
50#![warn(clippy::pedantic)]
51#![deny(unsafe_code)]
52#![deny(unsafe_op_in_unsafe_fn)]
53#![deny(nonstandard_style)]
54#![deny(missing_debug_implementations)]
55#![deny(missing_docs)]
56#![deny(rustdoc::broken_intra_doc_links)]
57#![allow(
58 clippy::inline_always,
59 reason = "hot-path predicate guards use #[inline(always)] intentionally for constant-folding"
60)]
61#![allow(
62 clippy::manual_let_else,
63 reason = "match can be clearer than let-else for some patterns"
64)]
65#![allow(
66 clippy::redundant_closure_for_method_calls,
67 reason = "causes clippy ICE on Rust 1.94; matches the workaround in workspace Cargo.toml"
68)]
69
70pub mod collections;
71pub mod consts;
72pub mod correctness;
73pub mod datetime;
74pub mod drop;
75pub mod env;
76pub mod hex;
77pub mod math;
78pub mod nanos;
79pub mod params;
80pub mod paths;
81pub mod serialization;
82pub mod shared;
83pub mod string;
84pub mod time;
85pub mod uuid;
86
87#[cfg(feature = "ffi")]
88pub mod ffi;
89
90#[cfg(feature = "python")]
91pub mod python;
92
93#[cfg(not(any(
94 target_os = "linux",
95 target_os = "macos",
96 target_os = "windows",
97 target_arch = "wasm32"
98)))]
99compile_error!("Unsupported platform: Nautilus supports only Linux, macOS, Windows, and wasm32");
100
101// Re-exports
102#[cfg(feature = "python")]
103pub use crate::params::from_pydict;
104pub use crate::{
105 collections::{AtomicMap, AtomicSet},
106 drop::CleanDrop,
107 nanos::UnixNanos,
108 params::Params,
109 shared::{SharedCell, WeakCell},
110 string::stack_str::{STACKSTR_CAPACITY, StackStr},
111 time::AtomicTime,
112 uuid::UUID4,
113};
114
115/// Message for when a mutex guard cannot be acquired due to poisoning.
116///
117/// Mutex guards should use `expect` rather than handle poison errors.
118/// A poisoned mutex indicates a thread panicked while holding the lock,
119/// meaning protected data may be in an inconsistent state. Propagating
120/// the panic is the idiomatic and safe approach, as continuing with
121/// potentially corrupted data would violate safety invariants.
122pub const MUTEX_POISONED: &str = "Mutex poisoned";