Skip to content

Comment on When static makes your C code 10 times fasterparent

Comments

I really wish Zig had followed Rust’s lead and made variables const by default :/

Variables are immutable by default in Rust, but they're not const by default. The difference is that a variable can become mutable while a const is always immutable.

How do you set a variable as mutable after the fact in rust?

You can do:

    let foo = "1234".to_string();
    let mut foo = foo;
    foo = "5678";
This only works if you have ownership of the variable though. And in practice it's a pretty good compromise, because it's pretty hard to do this by mistake.

Note: const in rust is different to const in some other languages: it represents a value that is duplicated inline into each use site at compile time.

Yes I think i see it more like constexpr.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.