use abi_stable::{ declare_root_module_statics, library::RootModule, package_version_strings, sabi_trait, sabi_types::{RMut, VersionStrings}, std_types::{RBox, RCowStr, ROk, ROption, RResult, RSome, RStr, RString, RVec}, StableAbi, }; mod error; pub use self::error::Error; /// The identifier for a plugin. #[repr(C)] #[derive(Debug, Clone, PartialEq, Eq, StableAbi, Hash)] #[sabi(impl_InterfaceType(Sync, Send, Debug, Debug, Hash))] pub struct PluginId { pub named: RCowStr<'static>, /// The number of the instance of this Plugin. pub instance: u64, } #[repr(C)] #[derive(StableAbi, Clone, Debug, Copy)] #[sabi(impl_InterfaceType(Sync, Send, Debug, Debug))] pub enum CoordType { Polar, Cartesian, Other, } pub type PluginType = Plugin_TO<'static, RBox<()>>; #[repr(C)] #[derive(StableAbi, Clone, Debug)] #[sabi(impl_InterfaceType(Sync, Send, Debug))] pub enum VecResult { I64(RVec), F64(RVec), I32(RVec), I16(RVec), F32(RVec), U64(RVec), U32(RVec), Bool(RVec), I8(RVec), U8(RVec), } #[repr(C)] #[derive(StableAbi, Clone, Copy, Debug)] #[sabi(impl_InterfaceType(Sync, Send, Debug))] pub enum DataShape { Scalar, Vector, Matrix, } #[repr(C)] #[derive(Debug, StableAbi, Clone)] pub struct MetaData { pub datetime: ROption, pub site_info: ROption, pub lat_range: ROption<[f64; 2]>, pub lon_range: ROption<[f64; 2]>, pub data_format: ROption, pub other_info: ROption, } #[repr(C)] #[derive(StableAbi, Clone, Debug)] #[sabi(impl_InterfaceType(Sync, Send, Debug))] pub enum PluginResultType { // Single R, V, SW, CC, ZDR, PHIDP, KDP, HCA, DBZ, QPE, QPF, VIL, OHP, THP, ET, EB, // Unknown Unknown, } #[repr(C)] #[derive(StableAbi, Clone, Debug)] #[sabi(impl_InterfaceType(Sync, Send, Debug))] pub struct PluginResult { pub datetime: RString, pub meta: MetaData, pub blocks: RVec, } #[repr(C)] #[derive(StableAbi, Clone, Debug)] #[sabi(impl_InterfaceType(Sync, Send, Debug))] pub struct Block { pub data: VecResult, pub shape: DataShape, pub size: RVec, pub coord_type: CoordType, pub datetime: i64, pub dimensions: RVec, pub dimension_values: RVec>, pub fill_value: f64, pub data_type: PluginResultType, } #[repr(C)] #[derive(Debug, StableAbi)] #[sabi(impl_InterfaceType(Sync, Send, Debug))] pub struct PluginInfo { pub name: RStr<'static>, pub version: RStr<'static>, pub author: RStr<'static>, pub description: ROption>, pub url: ROption>, } #[sabi_trait] #[sabi(impl_InterfaceType(Sync, Send, Debug))] pub trait Plugin: Send + Sync { fn load(&self, path: RStr<'_>) -> RResult; fn plugin_id(&self) -> &PluginId; fn plugin_info(&self) -> PluginInfo; } /// The root module of a`plugin` dynamic library. /// /// To load this module, /// call ::load_from_directory(some_directory_path) #[repr(C)] #[derive(StableAbi)] #[sabi(impl_InterfaceType(Sync, Send, Debug))] #[sabi(kind(Prefix(prefix_ref = PluginMod_Ref)))] #[sabi(missing_field(panic))] pub struct PluginMod { /// Constructs the plugin. /// /// /// The `#[sabi(last_prefix_field)]` attribute here means that this is the last field in this struct /// that was defined in the first compatible version of the library /// (0.1.0, 0.2.0, 0.3.0, 1.0.0, 2.0.0 ,etc), /// requiring new fields to always be added below preexisting ones. /// /// The `#[sabi(last_prefix_field)]` attribute would stay on this field until the library /// bumps its "major" version, /// at which point it would be moved to the last field at the time. /// #[sabi(last_prefix_field)] pub new: extern "C" fn(PluginId) -> RResult, } impl RootModule for PluginMod_Ref { declare_root_module_statics! {PluginMod_Ref} const BASE_NAME: &'static str = "plugin"; const NAME: &'static str = "plugin"; const VERSION_STRINGS: VersionStrings = package_version_strings!(); }