How to resize a memmap?

I have a memmap:: Mmap object, which was created from MmapOptions:

let mut mmap_opts = MmapOptions::new();
let my_map = unsafe {
    mmap_opts
        .offset(offset)
        .len(matrix_len)
        .map(&read.get_ref())
        .map_err(|e| ErrorKind::io_error("[Some error message here]", e))?
    };

Now I want to create a new Mmap based on my_map I created above: Every parameter remains the same, except len, because I want to make the len value smaller.

I don't see any function in memmap's documentation that I can use for changing len, since Mmap's only field is Innermap (which contains len as its field), but Innermap is private.

What are the options that I can take to make this possible? Any ideas would help!

I have built ::memmap's documentation with private items included to make looking at the crate internals / innards easier.

So the key thing here is that there are two different implementations, one linux-based, and another windows-based.

According to this SO question, implementing linux's mremap functionality (what you seem to be looking for) is not impossible but it is complex. So maybe you are looking for a linux-only solution.

In which case you can indeed go and fork the crate's respository, and under a correctly #[cfg]-gated interface, do make a publicly accessible API thats allows using mremap under the hood.

Then go submit a PR with those changes (so that other people can benefit from them), and in the meantime, use Cargo.toml's [patch.crates-io] section to redefine the memmap dependency but this time targetting your repository.