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::assert_is_empty,
35 reason = "`assert!(x.is_empty())` is clearer than comparing against an empty value"
36)]
37
38/// ABI version of the public plug-in metadata contract.
39///
40/// The host refuses to load a plug-in whose
41/// [`PluginManifest::abi_version`](crate::manifest::PluginManifest::abi_version)
42/// does not match this value.
43pub const NAUTILUS_PLUGIN_ABI_VERSION: u32 = 1;
44
45/// Schema version for [`manifest::PluginBuildId`].
46pub const PLUGIN_BUILD_ID_VERSION: u32 = 1;
47
48/// Name of the single `extern "C"` entry symbol every plug-in cdylib exports.
49pub const NAUTILUS_PLUGIN_INIT_SYMBOL: &[u8] = b"nautilus_plugin_init";
50
51pub mod boundary;
52#[cfg(feature = "component-binding")]
53#[doc(hidden)]
54pub mod component;
55pub mod host;
56pub mod manifest;
57pub mod panic;
58
59mod macros;
60
61pub use boundary::{BorrowedStr, OwnedBytes, PluginError, PluginErrorCode, PluginResult, Slice};
62pub use host::{HostContext, HostVTable};
63pub use manifest::{PluginBuildId, PluginInitFn, PluginManifest};
64
65/// Re-exports that plug-in crates typically want in scope.
66pub mod prelude {
67 pub use crate::{
68 BorrowedStr, HostContext, HostVTable, NAUTILUS_PLUGIN_ABI_VERSION, PluginBuildId,
69 PluginError, PluginErrorCode, PluginManifest, PluginResult, Slice,
70 };
71}
72
73#[cfg(test)]
74mod tests {
75 use rstest::rstest;
76
77 use super::*;
78
79 #[rstest]
80 fn init_symbol_matches_exported_entrypoint() {
81 assert_eq!(NAUTILUS_PLUGIN_INIT_SYMBOL, b"nautilus_plugin_init");
82 }
83}