Skip to main content

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 message;
79pub mod nanos;
80pub mod params;
81pub mod paths;
82pub mod serialization;
83pub mod shared;
84pub mod string;
85pub mod time;
86pub mod uuid;
87
88#[cfg(feature = "ffi")]
89pub mod ffi;
90
91#[cfg(feature = "python")]
92pub mod python;
93
94#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
95compile_error!("Unsupported platform: Nautilus supports only Linux, macOS, and Windows");
96
97// Re-exports
98#[cfg(feature = "python")]
99pub use crate::params::from_pydict;
100pub use crate::{
101    collections::{AtomicMap, AtomicSet},
102    drop::CleanDrop,
103    nanos::UnixNanos,
104    params::Params,
105    shared::{SharedCell, WeakCell},
106    string::stack_str::{STACKSTR_CAPACITY, StackStr},
107    time::AtomicTime,
108    uuid::UUID4,
109};
110
111/// Message for when a mutex guard cannot be acquired due to poisoning.
112///
113/// Mutex guards should use `expect` rather than handle poison errors.
114/// A poisoned mutex indicates a thread panicked while holding the lock,
115/// meaning protected data may be in an inconsistent state. Propagating
116/// the panic is the idiomatic and safe approach, as continuing with
117/// potentially corrupted data would violate safety invariants.
118pub const MUTEX_POISONED: &str = "Mutex poisoned";