this post was submitted on 09 Jun 2025
90 points (95.0% liked)

Programmer Humor

36519 readers
254 users here now

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

Rules:

founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 5 points 1 week ago* (last edited 1 week ago)

To explain

There are 2 Error struct / enum declarations, probably in separate files

To the ?, they are different types and cannot be converted from one to the other (because they are two disparate structs that happen to have the same name, but can have different bodies)

To fix this

You can either use .some_func_result().map_err(|err| /* conversion here/*)?; +

Or you can impl From<Error1> for Error2

And you should also name it ThingError, so you can visually differentiate the two


+ There are like 10 different mapping functions, depending on if you're using an option or a result

I never remember which one specifically i need, (unwrap_or, map_or, map_or_else, ok, ok_or)

I usually just hunt through the auto complete list until i find the function signature that gives me what i need