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 codecs.
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//! - `extension-module`: Builds as a Python extension module.
46//! - `ffi`: Enables the C foreign function interface (FFI) from
47//!   [cbindgen](https://crates.io/crates/cbindgen).
48//! - `python`: Enables Python bindings from [PyO3](https://pyo3.rs).
49//! - `simulation`: Enables deterministic simulation testing with
50//!   [MadSim](https://crates.io/crates/madsim).
51
52#![warn(rustc::all)]
53#![warn(clippy::pedantic)]
54#![allow(
55    clippy::manual_let_else,
56    clippy::option_if_let_else,
57    clippy::or_fun_call,
58    clippy::redundant_else,
59    clippy::similar_names,
60    clippy::single_match_else,
61    reason = "workspace policy; generated by scripts/update-clippy-allowances.py"
62)]
63#![deny(unsafe_code)]
64#![deny(unsafe_op_in_unsafe_fn)]
65#![deny(nonstandard_style)]
66#![deny(missing_debug_implementations)]
67#![deny(missing_docs)]
68#![deny(rustdoc::broken_intra_doc_links)]
69#![allow(
70    clippy::inline_always,
71    reason = "hot-path predicate guards use #[inline(always)] intentionally for constant-folding"
72)]
73#![allow(
74    clippy::assert_is_empty,
75    reason = "`assert!(x.is_empty())` is clearer than comparing against an empty value"
76)]
77
78pub mod collections;
79pub mod consts;
80pub mod correctness;
81pub mod datetime;
82pub mod env;
83pub mod hex;
84pub mod interval;
85pub mod math;
86pub mod nanos;
87pub mod params;
88pub mod paths;
89pub mod serialization;
90pub mod shared;
91pub mod string;
92pub mod time;
93pub mod uuid;
94
95#[cfg(feature = "ffi")]
96pub mod ffi;
97
98#[cfg(feature = "python")]
99pub mod python;
100
101#[cfg(not(any(
102    target_os = "linux",
103    target_os = "macos",
104    target_os = "windows",
105    target_arch = "wasm32"
106)))]
107compile_error!("Unsupported platform: Nautilus supports only Linux, macOS, Windows, and wasm32");
108
109// Re-exports
110pub use interval::ClosedInterval;
111
112#[cfg(feature = "python")]
113pub use crate::params::from_pydict;
114pub use crate::{
115    collections::{AtomicMap, AtomicSet},
116    nanos::{DurationNanos, DurationNanosOutOfRangeError, UnixNanos},
117    params::Params,
118    shared::{SharedCell, WeakCell},
119    string::stack_str::{STACKSTR_CAPACITY, StackStr},
120    time::AtomicTime,
121    uuid::UUID4,
122};