Why does memmap2 use MmapMut and Mmap

Context: memmap2::MmapMut - Rust

Normally, I would expect there to be one struct Mmap and functions on

Mmap
&Mmap
&mut Mmap

but instead, we have a custom type MmapMut. Why ?

This is because marking memory read-only or mutable requires calling the mprotect function, so conversion between the two kinds of memory maps should be explicit. The MmapMut type represents a memory map currently configured to be mutable.

Note that given an &MmapMut, it is not possible to modify the memory through that immutable reference.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.