Greg KH: Untrusted data in Linux – How Rust is going to save us [video]
youtube.com2 pointsby NobodyNada0 comments
if fooOK
if barOK {
if bazOK {
// do something
}
}
}
can be written as: guard fooOK else { return }
guard barOK else { return }
guard bazOK else { return }
// do something
Obviously there are other options (like writing a negated if), but sometimes guard is more readable. It's a style thing. guard let foo = someOptional else { return }
print(foo);
This is useful enough that Rust copied it in the form of 'let ... else {}' statements (but did not bring over boolean guard statements).
Things are slowly getting better here! '&raw'/'&raw mut' reference operators were stabilized a couple years ago.
Another ergonomic improvement in the pipeline is a better way to access fields behind pointers, something like C's -> operator. This is taking some time to design because there are things other than raw pointers that would benefit from a generalized field projection mechanism, like Pin, NonNull, and (potentially user-defined) smart pointer types.