Rust is so cool, how about you?

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? :slight_smile:

2 Likes

The fact that it taught me parallel programming without the pain of gotchas like race conditions.

5 Likes

Error messages!

6 Likes

No data races.

5 Likes

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...

1 Like
  • Decent unit testing and documentation integrated out of the box. No longer have to worry about installing doxygen or what testing lib to use.
  • build system. Remember bundler and rake, and rbenv and rvm and gem and ohhh, thank you but no thanks.
  • memory safety, performance and high level language combined, and fearless concurrency/threading. It is not original to say it, but it's a big deal really. And languages like ruby and python don't even support multi threading.
  • WASM I am so happy I no longer have to write Js.
2 Likes

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...

9 Likes

Lowkey coolest thing about Rust is that it supports nested block comments :sunglasses:

5 Likes

The thing I like most about Rust is how powerful its type system is.

7 Likes
  • OsStr/OsString
  • The type system. Just look at how elegantly 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.
  • The error messages
  • async/await
  • Macros
1 Like

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.

1 Like

Woah! :open_mouth:

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.

4 Likes

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.

2 Likes

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()
}
4 Likes

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.

3 Likes

About 100 things that combine to make "if it compiles, it works!" basically a reality. Rust is a groundbreaking achievement.

9 Likes
  • no header files (looking at you, C/C++)
  • ::<> instead of having to deal with <<…> > (hint: the space is important :man_facepalming:t3:)
  • automatic drop-code insertion
3 Likes

Rust is so cool, how about you?

Hey, just call me Fonzie, I'm cool :slight_smile:

Didn't they fix that requirement for a space in recent C++ ?

1 Like

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.