From 473bd5a57c4d1c34690c495b66964ff855a2cd18 Mon Sep 17 00:00:00 2001 From: Illyrius <28700752+illyrius666@users.noreply.github.com> Date: Sun, 8 Feb 2026 14:11:40 +0100 Subject: [PATCH] chore(docs): docs/pumpkin-api-macros (#1450) * updated documentations and applied a minor fix to resource_pack.rs config (suggested and autofixed by rustrover). * fmt Signed-off-by: Illyrius * docs Signed-off-by: Illyrius * fix unnecessary spaces --------- Signed-off-by: Illyrius Signed-off-by: Illyrius <28700752+illyrius666@users.noreply.github.com> Co-authored-by: Illyrius --- pumpkin-api-macros/src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pumpkin-api-macros/src/lib.rs b/pumpkin-api-macros/src/lib.rs index 1618af3a0..9b75d974c 100644 --- a/pumpkin-api-macros/src/lib.rs +++ b/pumpkin-api-macros/src/lib.rs @@ -7,9 +7,13 @@ use std::sync::LazyLock; use std::sync::Mutex; use syn::{ImplItem, ItemFn, ItemImpl, ItemStruct, parse_macro_input, parse_quote}; +/// Stores all functions annotated with `#[plugin_method]` for later use in the impl. static PLUGIN_METHODS: LazyLock>> = LazyLock::new(|| Mutex::new(HashMap::new())); +/// Marks a function as a plugin method, wrapping it to return a `PluginFuture`. +/// +/// The function body will be executed asynchronously using the global runtime. #[proc_macro_error] #[proc_macro_attribute] pub fn plugin_method(_attr: TokenStream, item: TokenStream) -> TokenStream { @@ -44,6 +48,10 @@ pub fn plugin_method(_attr: TokenStream, item: TokenStream) -> TokenStream { TokenStream::new() } +/// Wraps a struct as a plugin implementation. +/// +/// This generates the `Plugin` impl for the struct, including all `#[plugin_method]` annotated functions, +/// and provides a `plugin()` function to return it as a boxed trait object. #[proc_macro_error] #[proc_macro_attribute] pub fn plugin_impl(_attr: TokenStream, item: TokenStream) -> TokenStream { @@ -98,6 +106,7 @@ pub fn plugin_impl(_attr: TokenStream, item: TokenStream) -> TokenStream { TokenStream::from(expanded) } +/// Wraps all functions in an `impl` block to execute with a runtime. #[proc_macro_error] #[proc_macro_attribute] pub fn with_runtime(attr: TokenStream, item: TokenStream) -> TokenStream {