this post was submitted on 18 Dec 2025
320 points (98.8% liked)

Programmer Humor

39542 readers
54 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 6 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] TimeSquirrel@kbin.melroy.org 3 points 2 days ago (7 children)

Is this just like the equivalent of a getter method in C++?

[–] brandon@piefed.social 1 points 2 days ago* (last edited 2 days ago) (5 children)

It's more like a method that can throw an exception. Rust doesn't really have exceptions, but if you have a Result or Option type you can Unwrap it to get just the T. But if there's no T to get (in the case of an Error type for Result for None for Option) the call panics.

[–] eldavi@lemmy.ml 1 points 2 days ago (4 children)

so you have to wrap everything in a try/catch?

[–] mkwt@lemmy.world 3 points 2 days ago (1 children)

It's worse than that. In C++, if you fail to catch an exception, then std::terminate() is called. In Rust the only options are roughly equivalent to C++ noexcept, or std::terminate() [panic in Rust]. There's nothing in between.

[–] eldavi@lemmy.ml 1 points 1 day ago

i've been meaning to get into rust; but i'm learning that i lack motivation if it's not part of my job and becoming a sysadmin again doesn't require it.

load more comments (2 replies)
load more comments (2 replies)
load more comments (3 replies)