46 lines
1.1 KiB
Rust
46 lines
1.1 KiB
Rust
|
|
// Code generated by ndpgen. DO NOT EDIT.
|
||
|
|
//
|
||
|
|
// This file contains export wrappers for the Lifecycle capability.
|
||
|
|
// It is intended for use in Navidrome plugins built with extism-pdk.
|
||
|
|
|
||
|
|
|
||
|
|
/// Error represents an error from a capability method.
|
||
|
|
#[derive(Debug)]
|
||
|
|
pub struct Error {
|
||
|
|
pub message: String,
|
||
|
|
}
|
||
|
|
|
||
|
|
impl std::fmt::Display for Error {
|
||
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||
|
|
write!(f, "{}", self.message)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
impl std::error::Error for Error {}
|
||
|
|
|
||
|
|
impl Error {
|
||
|
|
pub fn new(message: impl Into<String>) -> Self {
|
||
|
|
Self { message: message.into() }
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// InitProvider provides the OnInit function.
|
||
|
|
pub trait InitProvider {
|
||
|
|
fn on_init(&self) -> Result<(), Error>;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Register the on_init export.
|
||
|
|
/// This macro generates the WASM export function for this method.
|
||
|
|
#[macro_export]
|
||
|
|
macro_rules! register_lifecycle_init {
|
||
|
|
($plugin_type:ty) => {
|
||
|
|
#[extism_pdk::plugin_fn]
|
||
|
|
pub fn nd_on_init(
|
||
|
|
) -> extism_pdk::FnResult<()> {
|
||
|
|
let plugin = <$plugin_type>::default();
|
||
|
|
$crate::lifecycle::InitProvider::on_init(&plugin)?;
|
||
|
|
Ok(())
|
||
|
|
}
|
||
|
|
};
|
||
|
|
}
|