Skip to main content

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    /// Signed `.wasm` **component** (Component Model + WIT). Surfaced by
30    /// discovery; the loader (`WasmComponentExecutor`) lands in FIDIUS-I-0021
31    /// Phase 2. Reserved now so routing and `PluginInfo` model all three
32    /// backends.
33    Wasm,
34}
35
36/// Owned metadata for a discovered or loaded plugin.
37///
38/// All data copied from FFI descriptor — no raw pointers. `capabilities` and
39/// `buffer_strategy` are cdylib-specific concepts; for python plugins they
40/// take their default values (0 / `PluginAllocated`) and have no runtime
41/// meaning.
42#[derive(Debug, Clone)]
43pub struct PluginInfo {
44    /// Human-readable plugin name (e.g., "BlurFilter").
45    pub name: String,
46    /// Interface trait name (e.g., "ImageFilter").
47    pub interface_name: String,
48    /// FNV-1a hash of required method signatures.
49    pub interface_hash: u64,
50    /// User-specified interface version.
51    pub interface_version: u32,
52    /// Capability bitfield (optional method support). Cdylib only.
53    pub capabilities: u64,
54    /// Buffer management strategy. Cdylib only.
55    pub buffer_strategy: BufferStrategyKind,
56    /// Runtime kind. New in 0.2 — defaults to `Cdylib` for backward
57    /// compatibility with code that constructs `PluginInfo` directly.
58    pub runtime: PluginRuntimeKind,
59}
60
61impl PluginInfo {
62    /// True if this is a cdylib-backed plugin.
63    pub fn is_cdylib(&self) -> bool {
64        matches!(self.runtime, PluginRuntimeKind::Cdylib)
65    }
66
67    /// True if this is a Python plugin.
68    pub fn is_python(&self) -> bool {
69        matches!(self.runtime, PluginRuntimeKind::Python)
70    }
71
72    /// True if this is a WASM component plugin.
73    pub fn is_wasm(&self) -> bool {
74        matches!(self.runtime, PluginRuntimeKind::Wasm)
75    }
76}
77
78/// Controls how strictly the host validates plugins.
79#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
80pub enum LoadPolicy {
81    /// Reject any validation failure, require signatures if configured.
82    #[default]
83    Strict,
84    /// Warn on unsigned plugins but allow loading.
85    Lenient,
86}