Multiple mutable references in scope


I’m still confused about the “no-op Drop” aspect. MmapMut does not implement Drop, so there must already be some Drop wrapper that is being provided over it (which does the flush in drop()). So isn’t that analogous to the Ref<'a> in the minimal example? Its Drop prevents multiple Refs being alive in the same scope.

memmap crate is available on the playground - perhaps we can switch to that with a more realistic example?


MmapMut itself is just a thin wrapper around the platform-specific MmapInner (which implements Drop and does the flushing implicitly by unmapping the memory).


Oh, I thought you were doing something more explicit than simply relying on munmap() (IIRC, that just leaves the page dirty in the pagecache and waits for the swapper to actually persist it to disk).

Ok, so it seems like you should be able to introduce a phantom lifetime, as suggested upthread, into your wrapper over MmapMut. If you can put a realistic looking example onto the playground, we can try to work something out. FWIW, I don’t personally think a no-op Drop impl, if that’s what it takes to convey the semantics, is a huge deal. Is it common? No. But there’re other things in Rust that aren’t as common, but are useful when needed.


I think I can finish the crate on my own from this point on. I’ll read through the nll rfc tomorrow and then finish my implementation. Once the first version is up on, I’ll probably come back here for feedback :wink:


Okay, I just released v0.0.2 of mmap-safe. The code is here:

After reading through the NLL-rfc, I feel a lot more comfortable with the code and believe this is the optimal solution to the problem. But I’m open for improvements.