Rework method chaining system of Rust generator#1602
Rework method chaining system of Rust generator#1602QuantumSegfault wants to merge 1 commit intobytecodealliance:mainfrom
Conversation
|
Requesting review. |
|
For For the implementation, personally I think returning Additionally for the implementation, would it make sense to give the |
|
It is indeed a duplicate, but with a couple of changes (filter by resource; but no import vs export). They probably could be dedupped to an extent...not sure how easily though. As for owning vs borrowing, in our use case its the difference between doing: let command = Command::new(&["fly".to_string()], "Gives you the ability to fly.");
let with_speed = CommandNode::argument(
"speed",
&pumpkin_plugin_api::command_wit::ArgumentType::Float((Some(0.0), Some(1.0))),
);
with_speed.execute(WithSpeedExecutor);
let no_speed = CommandNode::argument(
"target",
&pumpkin_plugin_api::command_wit::ArgumentType::Players,
);
no_speed.execute(NoSpeedExecutor).then(with_speed);
command.then(no_speed).execute(BaseExecutor);vs: let mut command = Command::new(&["fly".to_string()], "Gives you the ability to fly.")
.then(
CommandNode::argument(
"target",
&pumpkin_plugin_api::command_wit::ArgumentType::Players,
)
.execute(NoSpeedExecutor)
.then(
CommandNode::argument(
"speed",
&pumpkin_plugin_api::command_wit::ArgumentType::Float((
Some(0.0),
Some(1.0),
)),
)
.execute(WithSpeedExecutor),
),
)
.execute(BaseExecutor);Have to break up the chain in reverse order instead of being able to have one atomic builder. EDIT: I cleaned up the "before" example to be a little more fair. As for exposing |
Follow up to #1586
After testing, #1586 had some major flaws in practice
&Self, which makes things like passing a method chain into a parameter expecting an own more cumbersome than necessary.This replaces the
--enable-method-chainingswitch with a--chainable-methodsparameter, that works similar to the current async filter. You can choose to opt-in to it for all methods, for all methods within a particular resource, or just for a particular method (or any combination of those).Additional, methods with method chaining enabled now take owning
selfinstead of the default borrowing&self, and are-> Selfrather than-> &Self. The ABI remains unaffected.