nautilus_plugin/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//! Plug-in artifact identity and boundary primitives for
17//! [NautilusTrader](https://nautilustrader.io).
18//!
19//! This crate provides the public contract that lets an independently compiled
20//! Rust cdylib identify itself to a Nautilus host. It defines versioned build
21//! metadata, allocator-safe boundary values, opaque host tokens, and the
22//! `nautilus_plugin!` macro for exporting the standard entry symbol and
23//! manifest.
24//!
25//! # Feature Flags
26//!
27//! This crate provides feature flags to control source code inclusion during compilation:
28//!
29//! - `component-binding`: Enables the experimental executable component contract.
30//! - `host`: Optional plug-in manifest compatibility flag.
31
32#![warn(clippy::pedantic)]
33#![allow(
34 clippy::manual_let_else,
35 clippy::option_if_let_else,
36 clippy::or_fun_call,
37 clippy::redundant_else,
38 clippy::similar_names,
39 clippy::single_match_else,
40 reason = "workspace policy; generated by scripts/update-clippy-allowances.py"
41)]
42#![allow(
43 clippy::assert_is_empty,
44 reason = "`assert!(x.is_empty())` is clearer than comparing against an empty value"
45)]
46
47/// ABI version of the public plug-in metadata contract.
48///
49/// The host refuses to load a plug-in whose
50/// [`PluginManifest::abi_version`](crate::manifest::PluginManifest::abi_version)
51/// does not match this value.
52pub const NAUTILUS_PLUGIN_ABI_VERSION: u32 = 1;
53
54/// Schema version for [`manifest::PluginBuildId`].
55pub const PLUGIN_BUILD_ID_VERSION: u32 = 1;
56
57/// Name of the single `extern "C"` entry symbol every plug-in cdylib exports.
58pub const NAUTILUS_PLUGIN_INIT_SYMBOL: &[u8] = b"nautilus_plugin_init";
59
60pub mod boundary;
61pub mod host;
62pub mod manifest;
63pub mod panic;
64
65mod macros;
66
67#[cfg(feature = "component-binding")]
68#[doc(hidden)]
69pub mod component;
70
71pub use boundary::{BorrowedStr, OwnedBytes, PluginError, PluginErrorCode, PluginResult, Slice};
72pub use host::{HostContext, HostVTable};
73pub use manifest::{PluginBuildId, PluginInitFn, PluginManifest};
74
75/// Re-exports that plug-in crates typically want in scope.
76pub mod prelude {
77 pub use crate::{
78 BorrowedStr, HostContext, HostVTable, NAUTILUS_PLUGIN_ABI_VERSION, PluginBuildId,
79 PluginError, PluginErrorCode, PluginManifest, PluginResult, Slice,
80 };
81}
82
83#[cfg(test)]
84mod tests {
85 use rstest::rstest;
86
87 use super::*;
88
89 #[rstest]
90 fn init_symbol_matches_exported_entrypoint() {
91 assert_eq!(NAUTILUS_PLUGIN_INIT_SYMBOL, b"nautilus_plugin_init");
92 }
93}