Hi everyone,
I've started to learn Rust, this language has huge potential and it isn't hard to learn, I like Rust... but I think Rust should be more strict (one way to do things) and handle lifetimes implicitely. So these are some of my impressions.
- Semicolon and
return
keyword
Golang, Python, Ruby, Swift, Groovy don't have semicolon, it isn't mandatory with JavaScript, I'm used to using the semicolon since I'm developping in C++ but is it a useful symbol to make compilation faster today? To return a value in Rust you can just use a value without the semicolon, BUT the return
keyword is mandatory since you can't do "early returns" without this keyword:
fn f() -> i32 {
if true {
// early return
return 123;
}
return 456; // alternative pattern, just use "456"
}
=> I think that the semicolon isn't useful, and that Rust creators should have kept the return
pattern since it will remain a mandatory keyword for "early returns"
- More than one keyword to create a loop?
loop, while, for
=> Golang can do that with one keyword
- Two syntaxes for references?
The following code is valid:
struct A {}
let mut mut_a: A = A{};
fn borrower1(a: &mut A) {
// Code
}
fn borrower2(ref mut a: A) {
// Code
}
// Equivalent
let b = &mut_a;
let ref c = mut_a;
=> Why &
and ref
?
- Any difference between a struct tuple and an alias tuple?
struct TupleFromStruct(f32, f32);
type TupleFromAlias = (f32, f32);
- Explicit lifetimes should be implicit
In Rust each parameter have different lifetimes, sometimes it's necessary to put explicit lifetimes (when you have more than one parameter), do you think someday the Rust compiler will handle the lifetime implicitely? I think it can