3 ms·
Rust is a relatively new programming language that features nearly all the good parts of C++ (e.g. struct, reference, RAII, move semantics, generics) and almost
by nayuki 7y ago
Rust is a relatively new programming language that features nearly all the good parts of C++ (e.g. struct, reference, RAII, move semantics, generics) and almost none of the bad parts (e.g. duplicate features, cryptic syntax, undefined behavior).
Your example in Rust would read like this:
// Definition
fn foo(a: u8, b: &u8, c: &mut u8) -> i32 {
a = 0; // Local change only
println!("{}", *b); // Read pointee
*c = 1; // Write pointee
return 2;
}
// Call site
let bar: u8 = 3;
let baz: u8 = 4;
let mut bajinga: u8 = 5;
foo(bar, &baz, &mut bajinga);
- steveklabnik 7y agoYou shouldn’t need the type annotations on the three variables, by the way.