Comment by LAC-Tech

Comment by LAC-Tech a day ago

11 replies

Zig is a systems programming language. I think that's probably who it's targeting.

People do systems programming in rust, but that's not really what most of the community is doing. And it's DEFINITELY not what the standard library is designed for.

konart a day ago

>People do systems programming in rust, but that's not really what most of the community is doing.

As someone who haven't done any systems programming after university: wait, what?

I was under impression that this is exactly what people where doing with Rust.(system apps, even linux kernel, no?)

If not - what do they (most if the community) are doing with Rust?

  • LAC-Tech a day ago

    Web servers, games, and applications, that sort of thing.

    Some people definitely do systems programming in, but it's a minority. The std library is not set up for it at all, you need something like rustix, but even that results in very unidiomatic ("unsafe") rust code.

    In Zig it's all in the std library by default. Because it's a systems programming language, first and foremost.

    • Ar-Curunir a day ago

      Rust is in the Linux kernel. Doesn’t get more systems than that…

    • porridgeraisin a day ago

      Actually I was also under OPs impression... can you tell me few specific problems with using rust for systems programming? BTW, I have only ever done something that resembles systems programming in C.

simonask a day ago

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]