I really like that you can define complex data structures using enum, struct, Vec, Rc etc. and use
#[derive(Debug)]
and
println!( "{:?}", x );
to automatically print it all out for debugging / error handling.
What do you find cool about Rust?
I really like that you can define complex data structures using enum, struct, Vec, Rc etc. and use
#[derive(Debug)]
and
println!( "{:?}", x );
to automatically print it all out for debugging / error handling.
What do you find cool about Rust?
The fact that it taught me parallel programming without the pain of gotchas like race conditions.
Error messages!
No data races.
Hours debugging pointer problems (as in C) are replaced by hours struggling with the compiler.
Traits.
Iterators.
Combines the advantages of both high and low levels.
Pattern matching and type system that look like maths.
Clean docs, builds without any weird tricks (no makefiles, no unusual deps), strong conventions, you can mostly understand code without comments, interesting community, cross-platform, good deps handling, community/Mozilla-driven...
If I were to list all the cool things I find in Rust and it's environment/ecosystem, from cargo init
to cargo deb
I would be here all month.
Now if only I could ever find my way around the docs...
Lowkey coolest thing about Rust is that it supports nested block comments
The thing I like most about Rust is how powerful its type system is.
OsStr
/OsString
CondVar
forces you to pass it an owned Mutex
by requiring a MutexGuard
). And the OpenSSL crate does some neat things with types to differentiate between the private and public key parts.async
/await
I love the confidence it gives because it removes whole sets of errors known from other languages. You compile the code and mostly the thing you can worry about is domain logic errors.
Another great thing coming from that confidence is ease of refactoring. I just don't worry I will break something. This allows to maintain cleaner code and fix technical debt more often.
Woah!
Ok, that helps.
The fact that it lets me sleep better at night knowing "since it compiled it'll probably run perfectly"
The reason can be broken down into things like the Powerful Type System, All the safety rules and Thread safety rules, The ownership system... It all boils down to peace of mind for me.
Above all the fact that it has functional features like ADTs,
first-class functions, and pattern matching while at the same
time compiling down to objects that can be linked into any other
program as though it were C. No runtime shenanigans or dancings
around automated memory management, it just works. Other
languages force you either to commit to a runtime (Ocaml) or to
forego functional features (C++). Rust means I can have the steak
and eat it.
match
is super cool
/// false color of an image
fn false_color(pixel: image::Rgb<u8>) -> image::Rgb<u8> {
let m = 255.0 / 43.0;
let r = match pixel[0] {
0..=43 => 255.0,
value @ 44..=86 => -m * (value as f32 - 86.0),
87..=172 => 0.0,
value @ 173..=215 => m * (value as f32 - 173.0),
216..=MAX => 255.0,
};
let g = match pixel[1] {
value @ 0..=43 => m * value as f32,
44..=128 => 255.0,
value @ 129..=172 => -m * (value as f32 - 172.0),
173..=MAX => 0.0,
};
let b = match pixel[2] {
0..=86 => 0.0,
value @ 87..=129 => m * (value as f32 - 87.0),
130..=213 => 255.0,
value @ 214..=MAX => -m * (value as f32 - 255.0),
};
image::Rgb([r as u8, g as u8, b as u8])
}
Iterators + generics + slices:
/// calculate the euclidean norm of the slice
pub fn norm2<T: Float>(slice: &[T]) -> T {
slice.iter().fold(T::zero(), |n, &i| (i * i) + n).sqrt()
}
/// calculate the dot product of two slices
pub fn dot<T: Num + Copy + std::iter::Sum>(slice1: &[T], slice2: &[T]) -> T {
slice1.iter().zip(slice2).map(|(&a, &b)| a * b).sum()
}
cargo deb
is damn cool, isn't it? Only discovered it recently.
A big cool thing for me is what I have seen called "hack without fear".
At some point my little projects, that generally start out as an experiments all stuffed into main()
get big enough and tortuous enough that I want to pull it apart into separate functions, modules, objects/methods, even traits if I'm ambitious. Or move things around between threads. And so on and whatever.
Normally I would be loath to do that so casually. I'd be worried about breaking things with memory use problems and data races. Introducing problems I will not find till the thing crashes and burns in production. Code rapidly gets solidified into something I don't want to mess with.
In Rust I just do it. Rust won't let me introduce such problems. It's kind of liberating.
About 100 things that combine to make "if it compiles, it works!" basically a reality. Rust is a groundbreaking achievement.
<<…> >
(hint: the space is important )Rust is so cool, how about you?
Hey, just call me Fonzie, I'm cool
Didn't they fix that requirement for a space in recent C++ ?
They fixed it in C++11, I think. That took them ~25 years, assuming they had templates since the beginning. I was yet to be born at that time, so I don't know.