eov_plugin_api/lib.rs
1//! The eov plugin API.
2//!
3//! An eov plugin is a native library (`cdylib`) that implements
4//! [`sdk::Plugin`] and exports it with [`export_plugin!`]. The host talks to
5//! it through a small, layout-checked ABI ([`abi`]) carrying JSON messages
6//! defined in [`protocol`]; the SDK hides both behind safe Rust types.
7//!
8//! ```no_run
9//! use eov_plugin_api::prelude::*;
10//!
11//! struct Counter {
12//! host: Host,
13//! }
14//!
15//! impl Plugin for Counter {
16//! fn create(host: Host, _init: PluginInit) -> Result<Self, String> {
17//! Ok(Self { host })
18//! }
19//!
20//! fn on_event(&self, event: HostEvent) -> Result<(), String> {
21//! if let HostEvent::FileOpened { file } = event {
22//! self.host.info(format!("{} opened", file.filename));
23//! }
24//! Ok(())
25//! }
26//! }
27//!
28//! eov_plugin_api::export_plugin!(Counter);
29//! ```
30//!
31//! A plugin package (`.eop`) is a tar archive holding `plugin.toml` (see
32//! [`manifest`]), the library and any `.slint` files and assets. See the
33//! crate README and `example-plugin/` for a complete walkthrough, and
34//! [`testing`] for unit-testing plugins without eov.
35
36pub mod abi;
37pub mod manifest;
38pub mod protocol;
39pub mod sdk;
40pub mod testing;
41
42pub use manifest::PluginManifest;
43
44/// Everything a plugin usually needs: `use eov_plugin_api::prelude::*;`.
45pub mod prelude {
46 pub use crate::abi::{FfiErrorKind, FilterView, RegionRequest, SlideRegion};
47 pub use crate::protocol::*;
48 pub use crate::sdk::{
49 Frame, Host, HostError, HostResult, Image, Job, Layer, Plugin, SlideReader, Surface,
50 };
51 pub use serde_json::{Map, Value, json};
52}
53
54/// Re-exports used by [`export_plugin!`]; not part of the public API.
55#[doc(hidden)]
56pub mod __private {
57 pub use abi_stable::library::{
58 __call_root_module_loader as call_root_module_loader, CheckTypeLayout, LibHeader,
59 RootModuleResult,
60 };
61}
62
63use std::path::PathBuf;
64use thiserror::Error;
65
66/// Errors raised while reading plugin packages and manifests.
67#[derive(Debug, Error)]
68pub enum PluginError {
69 #[error("plugin manifest error in '{plugin_id}': {message}")]
70 Manifest { plugin_id: String, message: String },
71 #[error("plugin '{plugin_id}' missing required file: {path}")]
72 MissingFile { plugin_id: String, path: PathBuf },
73 #[error("duplicate plugin id: '{0}'")]
74 DuplicateId(String),
75 #[error("IO error: {0}")]
76 Io(#[from] std::io::Error),
77 #[error("{0}")]
78 Other(String),
79}
80
81pub type PluginResult<T> = Result<T, PluginError>;
82
83/// How a plugin's icon is provided in its manifest.
84#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
85#[serde(tag = "kind", rename_all = "snake_case")]
86pub enum IconDescriptor {
87 /// Inline SVG.
88 Svg { data: String },
89 /// Path to an image, relative to the plugin root.
90 File { path: PathBuf },
91}
92
93/// A discovered plugin package: its extracted root and parsed manifest.
94#[derive(Debug, Clone)]
95pub struct PluginDescriptor {
96 /// Absolute path to the extracted plugin root.
97 pub root: PathBuf,
98 pub manifest: PluginManifest,
99}