Attribute Macro bank
#[bank]Available on crate feature
bank only.Expand description
Mark a function, static, impl block, or trait as banked.
Everything banked is Warp-colored, the same way async colors code: a
-> R becomes -> impl Warp<Output = R>, captured by the call and run with
.drive() (the Future / .await model). The forms:
- On a function
fn f(a: A) -> R(generic or not): the body moves to the bank andf(a)returnsimpl Warp<Output = R>. Generics are carried onto the wrapper, so each instantiation is banked independently. - On a static: the data moves to the bank and a
Farto it is exposed. - On an impl block: every method is rewritten the same way, the receiver
becoming the first argument. Call as
value.method(args).drive(). - On a trait: each method signature is colored to
-> impl Warp<..>(RPITIT), exactly as anasync fnin a trait desugars. A#[bank] implof that trait then supplies the bodies.
Inside any banked body the ambient bank token is injected, and .drive (run a
Warp), .invoke (a far dispatch), and .there (borrow far data) are threaded
onto it automatically.
§Examples
ⓘ
#[bank]
pub static TABLE: [u8; 4] = [1, 2, 3, 4];
#[bank]
pub fn play(note: u8) -> u8 {
let base = TABLE.there(|t| t[0]); // borrow banked data
note.wrapping_add(base)
}
pub struct Point { pub x: u8, pub y: u8 }
#[bank]
impl Point {
pub fn shift(&self, dx: u8) -> u8 { self.x.wrapping_add(dx) }
}
// call site: `p.shift(3).drive()`