I am using the genawaiter crate to step thought the parsing of a custom programming language. The genawaiter crate allows for generator-like behavior using async/await. I need to be able to access the current parse tree, modified within the generator, from outside. I have program nodes currently written as methods (functions with &mut self).
I came up with two solutions, neither or which I could get rust to agree with:
- I hold the parse tree in a RwLock outside and pass it into the generator by ref. Then, when stepping, I move the self ref into a function that drops it, yields, then regrabs and returns the mut ref from somewhere in the Rwlocked tree. I wasn't able to change the
&mut self
to aself:RwLockReadGuard<'a, Self>
however. - I hold the parse tree in a RwLock inside the generator. I change the
&mut self
to a custom pointer that on deref, grabs the node from the tree. I think I can do this with projection (self: <NodeRef as Deref>::Target
). Then I can easily pass a ref to the tree back when yielding.
I was unable to get rust to allow either of these solutions due to lifetime issues. Is there a better way to do this that I didn't think of or is this just impossible with the crate and/or the way I am using it?