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#![deny(unsafe_code)]
55#![deny(unsafe_op_in_unsafe_fn)]
56#![deny(nonstandard_style)]
57#![deny(missing_debug_implementations)]
58#![deny(missing_docs)]
59#![deny(rustdoc::broken_intra_doc_links)]
60#![allow(
61 clippy::inline_always,
62 reason = "hot-path predicate guards use #[inline(always)] intentionally for constant-folding"
63)]
64#![allow(
65 clippy::manual_let_else,
66 reason = "match can be clearer than let-else for some patterns"
67)]
68#![allow(
69 clippy::assert_is_empty,
70 reason = "`assert!(x.is_empty())` is clearer than comparing against an empty value"
71)]
72
73pub mod collections;
74pub mod consts;
75pub mod correctness;
76pub mod datetime;
77pub mod env;
78pub mod hex;
79pub mod interval;
80pub mod math;
81pub mod nanos;
82pub mod params;
83pub mod paths;
84pub mod serialization;
85pub mod shared;
86pub mod string;
87pub mod time;
88pub mod uuid;
89
90#[cfg(feature = "ffi")]
91pub mod ffi;
92
93#[cfg(feature = "python")]
94pub mod python;
95
96#[cfg(not(any(
97 target_os = "linux",
98 target_os = "macos",
99 target_os = "windows",
100 target_arch = "wasm32"
101)))]
102compile_error!("Unsupported platform: Nautilus supports only Linux, macOS, Windows, and wasm32");
103
104// Re-exports
105pub use interval::ClosedInterval;
106
107#[cfg(feature = "python")]
108pub use crate::params::from_pydict;
109pub use crate::{
110 collections::{AtomicMap, AtomicSet},
111 nanos::{DurationNanos, DurationNanosOutOfRangeError, UnixNanos},
112 params::Params,
113 shared::{SharedCell, WeakCell},
114 string::stack_str::{STACKSTR_CAPACITY, StackStr},
115 time::AtomicTime,
116 uuid::UUID4,
117};