← Back to context

Comment by Sophira

4 days ago

We need people who can (and do) write in C, assembly, and all these low-level languages. Otherwise, software will just get slower and slower.

Rust has the same low-level memory model as C without the footguns.

  • Rust certainly does have some improvements, but I'm not 100% certain that it's the best tool for all low-level software. For example, I'm experimenting with Rust for some filesystem type code and I can't figure out how to write/read a struct to/from disk all at once. I'm brand new to Rust, so it's quite possible that it can be done and I just don't know the technique. Basically, I'm looking for something in Rust analogous to C's fread/fwrite. I know I can write out each field of the struct individually, but when the struct has many fields it means having to write a huge amount of nasty boilerplate code when in C it's a single function call (fread/fwrite).

    • This is generally unsafe, so to make it safe there needs to be something that restricts what kind of things you can read and write.

      For example, if your structure contains a reference, and you read an instance of that from disk, then you now have a potentially invalid reference, bypassing Rust's guarantees. Reading a structure of i32 numbers is safe, but it also has endianness footguns.

      The zerocopy crate implements traits and gives you a derive macro to mark types as being safe to serialize/deserialize in a safe way.

    • I think you're going to want to reach for serde. Its a bit of annotating but you can then de/serialize structs to arbitrary formats with one call.

      1 reply →

  • I love Rust but we really got to stop the link between C and Rust.

    If someone mentions C, that's not a free invite to start educating them on why they SHOULD use Rust. No one at the party is going to talk to you again that night