News for hackers. Stuff that matters.
Re:Zig, Rust, and Other Languages by Ygg2 on Friday March 15, 2024 @10:00PM (#39722669)
> Rust: `&str`, 'some bytes, and a length', 'Constructing a non-UTF-8 string slice is not immediate undefined behavior

If you're constructing invalid `str` you already have severely fucked up. And dog is eating your HDD.

Re:Zig, Rust, and Other Languages by DinaCoder98 on Friday March 15, 2024 @10:16PM (#39722730)
> If you're constructing invalid `str` you already have severely fucked up.

Presumably it'd be better to know this immediately on initialization of the variable rather than at some point in the program that actually expects valid utf8—god forbid you transmit or persist the data before this happens.

Re:Zig, Rust, and Other Languages by duped on Friday March 15, 2024 @10:31PM (#39722815)
That's why str::from_utf8 returns Result<&str, FromUtf8Error>. And if you know the string is UTF-8 encoded and don't want to pay the cost, there's `from_utf8_unchecked`, which is marked unsafe.
Re:Zig, Rust, and Other Languages by DinaCoder98 on Friday March 15, 2024 @11:17PM (#39723059)
Ah, I thought you were referring to the benefits of such a system as compared to zig and blithely passing the responsibility of input validation on to the programmer. Rust of course demonstrates the benefit of checking validity at initialization.