feat(plugin-api): Better method chaining (Rust) (#3045)

* feat(plugin-api): Better method chaining (Rust)

* Work around faulty force-link of `cabi_realloc`

* Stub for `pumpkin-plugin-api` as well

* Revert "Work around faulty force-link of `cabi_realloc`"

This reverts commit 4aa4d4370b.
This commit is contained in:
Demetrius Kanios
2026-08-24 23:03:11 -07:00
committed by GitHub
parent 5bf6349900
commit 67eaa91400
4 changed files with 75 additions and 64 deletions

View File

@@ -109,9 +109,7 @@ impl Command {
.unwrap_or_else(|e| e.into_inner())
.insert(id, Box::new(handler));
self.execute_with_handler_id(id);
self
self.execute_with_handler_id(id)
}
}
@@ -129,9 +127,7 @@ impl CommandNode {
.unwrap_or_else(|e| e.into_inner())
.insert(id, Box::new(handler));
self.execute_with_handler_id(id);
self
self.execute_with_handler_id(id)
}
/// Attaches a server-side suggestion handler to this argument node.
@@ -147,9 +143,7 @@ impl CommandNode {
.unwrap_or_else(|e| e.into_inner())
.insert(id, Box::new(handler));
self.suggest_with_handler_id(id);
self
self.suggest_with_handler_id(id)
}
}

View File

@@ -176,7 +176,11 @@ mod wit {
skip: ["init-plugin"],
path: "../pumpkin-plugin-wit/v0.1",
world: "plugin",
enable_method_chaining: true
chainable_methods: [
"pumpkin:plugin/command@0.1.0#command",
"pumpkin:plugin/command@0.1.0#command-node",
"pumpkin:plugin/text@0.1.0#text-component"
]
});
use super::Component;
@@ -463,3 +467,16 @@ pub mod persistent_data;
pub use persistent_data::PersistentDataHolder;
/// Game rules definitions and values.
pub use wit::pumpkin::plugin::game_rules::{GameRule, GameRuleValue};
/// Stub for component model `cabi_realloc`
/// Remove me after bytecodealliance/wit-bindgen#1697 makes it to release
#[cfg(not(target_arch = "wasm32"))]
#[unsafe(no_mangle)]
pub extern "C" fn cabi_realloc(
_old_ptr: *mut u8,
_old_len: usize,
_align: usize,
_new_len: usize,
) -> *mut u8 {
panic!("Call to cabi_realloc on native?")
}