fidius_host/types.rs
1// Copyright 2026 Colliery, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
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//! Owned metadata types for loaded plugins.
16
17use fidius_core::descriptor::BufferStrategyKind;
18
19/// Plugin runtime kind. Mirrors `fidius_core::package::PackageRuntime` and
20/// surfaces it in the host-facing `PluginInfo`. Re-exported here so host
21/// callers don't need a transitive `fidius-core` use.
22#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23pub enum PluginRuntimeKind {
24 /// Cdylib + `PluginRegistry` (the original fidius substrate).
25 Cdylib,
26 /// `.py` package loaded via `fidius-python`'s embedded interpreter.
27 /// Only produced when the `python` feature is enabled on `fidius-host`.
28 Python,
29}
30
31/// Owned metadata for a discovered or loaded plugin.
32///
33/// All data copied from FFI descriptor — no raw pointers. `capabilities` and
34/// `buffer_strategy` are cdylib-specific concepts; for python plugins they
35/// take their default values (0 / `PluginAllocated`) and have no runtime
36/// meaning.
37#[derive(Debug, Clone)]
38pub struct PluginInfo {
39 /// Human-readable plugin name (e.g., "BlurFilter").
40 pub name: String,
41 /// Interface trait name (e.g., "ImageFilter").
42 pub interface_name: String,
43 /// FNV-1a hash of required method signatures.
44 pub interface_hash: u64,
45 /// User-specified interface version.
46 pub interface_version: u32,
47 /// Capability bitfield (optional method support). Cdylib only.
48 pub capabilities: u64,
49 /// Buffer management strategy. Cdylib only.
50 pub buffer_strategy: BufferStrategyKind,
51 /// Runtime kind. New in 0.2 — defaults to `Cdylib` for backward
52 /// compatibility with code that constructs `PluginInfo` directly.
53 pub runtime: PluginRuntimeKind,
54}
55
56impl PluginInfo {
57 /// True if this is a cdylib-backed plugin.
58 pub fn is_cdylib(&self) -> bool {
59 matches!(self.runtime, PluginRuntimeKind::Cdylib)
60 }
61
62 /// True if this is a Python plugin.
63 pub fn is_python(&self) -> bool {
64 matches!(self.runtime, PluginRuntimeKind::Python)
65 }
66}
67
68/// Controls how strictly the host validates plugins.
69#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
70pub enum LoadPolicy {
71 /// Reject any validation failure, require signatures if configured.
72 #[default]
73 Strict,
74 /// Warn on unsigned plugins but allow loading.
75 Lenient,
76}