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;
61#[cfg(feature = "component-binding")]
62#[doc(hidden)]
63pub mod component;
64pub mod host;
65pub mod manifest;
66pub mod panic;
67
68mod macros;
69
70pub use boundary::{BorrowedStr, OwnedBytes, PluginError, PluginErrorCode, PluginResult, Slice};
71pub use host::{HostContext, HostVTable};
72pub use manifest::{PluginBuildId, PluginInitFn, PluginManifest};
73
74/// Re-exports that plug-in crates typically want in scope.
75pub mod prelude {
76 pub use crate::{
77 BorrowedStr, HostContext, HostVTable, NAUTILUS_PLUGIN_ABI_VERSION, PluginBuildId,
78 PluginError, PluginErrorCode, PluginManifest, PluginResult, Slice,
79 };
80}
81
82#[cfg(test)]
83mod tests {
84 use rstest::rstest;
85
86 use super::*;
87
88 #[rstest]
89 fn init_symbol_matches_exported_entrypoint() {
90 assert_eq!(NAUTILUS_PLUGIN_INIT_SYMBOL, b"nautilus_plugin_init");
91 }
92}