mysql_plugin_api/lib.rs
1#![warn(missing_docs)]
2#![doc = "Helper library for implementing MySQL plugins in Rust"]
3
4/// Global MySQL constants.
5pub mod constants;
6
7/// MySQL data structures.
8pub mod types;
9
10/// Macro to help declare MySQL plugins.
11///
12/// **ATTENTION**: Only use this macro once per plugin crate.
13///
14/// # Example
15///
16/// ```rust
17/// # use mysql_plugin_api::constants::MYSQL_HANDLERTON_INTERFACE_VERSION;
18/// # use mysql_plugin_api::mysql_declare_plugin;
19/// # use mysql_plugin_api::types::{Plugin, StorageEngineInfo, PluginType, License};
20/// # use std::ffi::c_void;
21/// pub const EXAMPLE_STORAGE_ENGINE: StorageEngineInfo = StorageEngineInfo {
22/// interface_version: MYSQL_HANDLERTON_INTERFACE_VERSION,
23/// };
24///
25/// mysql_declare_plugin![
26/// Plugin {
27/// plugin_type: PluginType::Storage,
28/// info: &EXAMPLE_STORAGE_ENGINE as *const _ as *const c_void,
29/// name: b"example\0" as *const u8,
30/// author: b"Felix Bytow\0" as *const u8,
31/// descr: b"Example storage engine in Rust\0" as *const u8,
32/// license: License::Bsd,
33/// ..Plugin::zero()
34/// },
35/// ];
36/// ```
37#[macro_export]
38macro_rules! mysql_declare_plugin {
39 ($( $plugin:expr ),+ $(,)?) => {
40 #[no_mangle]
41 pub static _mysql_plugin_interface_version_: i32 = $crate::constants::MYSQL_PLUGIN_INTERFACE_VERSION;
42
43 #[no_mangle]
44 pub static _mysql_sizeof_struct_st_plugin_: i32 = std::mem::size_of::<$crate::types::Plugin>() as i32;
45
46 #[no_mangle]
47 pub static _mysql_plugin_declarations_: [
48 $crate::types::Plugin;
49 <[$crate::types::Plugin]>::len(&[$( $plugin, )*]) + 1
50 ] = [
51 $( $plugin, )*
52 $crate::types::Plugin::zero()
53 ];
54 }
55}