Accessing to mutable object from outside of closure in single threaded example


I’m doing single threaded event loop application with some custom callback system, but after making all application design and coding I faced an issue with closures.
So Here what I have

let mut n = SomeObject::new("test1");
n.on_pending_conn(Box::new(|ev: Arc<Event>| {
      println!("Got Event from -> {}", ev.from);
      // how properly get access for "n" as a mutable object ?

Closure and program itself is inside single thread, so I don’t need any Mutex or RwLock or Arc, but I can’t find out how to do this ?



Use a RefCell; it’s basically a single-threaded version of RwLock. Also, you might find the Choosing Your Guarantees chapter of the rust book interesting.