3 ms·
> Perhaps the problem isn't C, but its standard library? That's certainly at least a factor. In Rust, the "reverse a string byte by byte" bit could look like:
by steveklabnik 4y ago
> Perhaps the problem isn't C, but its standard library?
That's certainly at least a factor. In Rust, the "reverse a string byte by byte" bit could look like:
let reversed_string = String::from_utf8(some_string.bytes().rev().collect::<Vec<u8>>())?;
This is just what I thought of first. Peeking at the standard library examples, this one is fun:
unsafe {
let vec = some_string.as_mut_vec();
vec.reverse();
}
This is unsafe because you may create invalid utf8, but we've already established that's not something we care about, so...
But yeah stuff like this isn't impossible in C, though you'd not have method call syntax, of course. Rust's libraries are just richer here.