#[macro_export]
macro_rules! nautilus_plugin {
(
$(name: $name:expr,)?
$(vendor: $vendor:expr,)?
$(version: $version:expr,)?
) => {
$crate::__nautilus_plugin_impl! {
@parse
name = ($($name)?),
vendor = ($($vendor)?),
version = ($($version)?),
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __nautilus_plugin_impl {
(
@parse
name = (),
$($rest:tt)*
) => {
::core::compile_error!("`nautilus_plugin!` requires a `name` field");
};
(
@parse
name = ($name:expr),
vendor = ($($vendor:expr)?),
version = (),
) => {
::core::compile_error!("`nautilus_plugin!` requires a `version` field");
};
(
@parse
name = ($name:expr),
vendor = ($($vendor:expr)?),
version = ($version:expr),
) => {
const _: () = {
static MANIFEST: ::std::sync::LazyLock<$crate::manifest::PluginManifest> =
::std::sync::LazyLock::new(|| $crate::manifest::PluginManifest {
abi_version: $crate::NAUTILUS_PLUGIN_ABI_VERSION,
plugin_name: $crate::boundary::BorrowedStr::from_str($name),
plugin_vendor: $crate::boundary::BorrowedStr::from_str(
$crate::__nautilus_plugin_impl!(@opt $($vendor)?),
),
plugin_version: $crate::boundary::BorrowedStr::from_str($version),
build_id: $crate::manifest::PluginBuildId::current(),
});
#[unsafe(no_mangle)]
pub unsafe extern "C" fn nautilus_plugin_init(
host: *const $crate::host::HostVTable,
) -> *const $crate::manifest::PluginManifest {
let result = ::std::panic::catch_unwind(|| {
if host.is_null() {
return ::core::ptr::null::<$crate::manifest::PluginManifest>();
}
&*MANIFEST as *const _
});
match result {
Ok(ptr) => ptr,
Err(payload) => {
$crate::panic::drop_payload(payload);
::core::ptr::null()
}
}
}
};
};
(@opt) => { "" };
(@opt $vendor:expr) => { $vendor };
}