with_!() { /* proc-macro */ }Expand description
Field-level borrow splitting macro.
See the fieldwork crate documentation for
detailed usage information.
§Syntax
with_!(receiver, {
methods {
method_name(&field1, mut field2, copy field3, arg: Type) -> ReturnType {
// method body
}
}
fields {
field_a
mut field_b
}
body {
// code that uses receiver.method_name() and receiver.field_x
}
});§Field Modes
fieldor&field— shared reference (&receiver.field)mut field— mutable reference (&mut receiver.field)copy field— by value, requiresCopytrait
§How It Works
The macro:
- Extracts fields from the receiver as separate local bindings
- Replaces
receiver.method()calls with inlined method bodies - Replaces
receiver.fieldaccesses with the local bindings
This allows the borrow checker to see that the borrows are disjoint.