What's the correct way to implement the equivalent of multiple mutable (statically allocated, statically dispatched, etc.) callbacks in Rust?
I have the following example code, which is the standard basis of event-driven APIs in other programming languages, but in Rust the borrow checker blocks it with "cannot borrow p1 as mutable more than once at a time": struct Pen { color_cmyk: u32, ink: usize, } impl Pen { pub fn new() -> Pen { Pen { color_cmyk: 0x80800000, ink: 20000, } } pub fn write(&mut self, text: &str) -> bool { if self.ink < text.len() { return false; } self.ink -= text.len(); true } } fn main() { println!("Hello, world !"); let mut p1 = Pen::new(); p1.write("Hello"); println!("ink: {}, color: {}", p1.ink, p1.color_cmyk)