Comment by simonask

Comment by simonask a day ago

6 replies

Which part of the Rust standard library are you referring to here?

As far as I can tell, it contains many, many features that are irrelevant outside of systems programming scenarios with highly particular needs.

LAC-Tech a day ago

Let me answer your question with a question - how do you memory map in rust with the standard library?

In zig it's std.posix.mmap.

  • tialaramex a day ago

    Because Rust's standard library doesn't provide memory mapping you will need to use platform specific APIs.

    In Zig it's exactly the same except that they decided to provide the POSIX platform specific APIs, which if you're using a POSIX system is I guess useful and otherwise it's dead weight.

    It's a choice. I don't think it's a good choice but it's a choice.

  • zelphirkalt a day ago

    Your question might hint at a questionable presumption. So let me answer your question with a question - Does one have to memory map in Rust? Perhaps there are alternatives available in Rust, that you are not considering.

  • simonask a day ago

    I think you are moving the goal posts. You use the `memmap2` crate, or the `libc` crate if you want to be reckless about it. The question was how the standard library gets in your way, not whether it includes everything you need.

    And I don't think that including every feature of every possible OS is a sensible position to have for a standard library. Or would you argue that it should also include things like `CreateWindowExW()`?

    If all you use is the Rust standard library, you can be reasonably sure that your program works on all platforms, and memory mapping is something that is highly platform specific, even among POSIX-likes. I would not like to attempt designing a singular cross-platform API for it that has to be maintained in perpetuity.

    (There are a few OS-specific APIs in the Rust standard library, mostly because they are required anyway for things like I/O and process management. But the limit has to be set somewhere.)

  • kryptiskt a day ago

        extern "C" mmap(addr:*mut c_void, length:c_size_t, prot:c_int, flags:c_int, fd:c_int, offset:c_ssize_t) -> *mut c_void;
    
    Piece of cake. Or you could install a crate with bindings if you are afraid of writing code yourself.
  • [removed] a day ago
    [deleted]