You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I sadly barely get to use ?, because I find myself not using Result<> as often because it just doesn't fit in. For example, I instead return a struct with a success boolean at one point, or I wanna completely ignore errors the other. There should be a way for ? to detect return values and use some trait to return an error.
For example:
structStuff{// some fields heresuccess:bool}implTryforStuff{fnerr(error: std::error::Error) -> Stuff{Stuff{// some fields heresuccess:false;}}}
Also, () return values would implement the trait as well, but return.. well... nothing.
If the suggestion sounds stupid to you - sorry for disturbing :(
The text was updated successfully, but these errors were encountered:
Your examples sound like they map to Result easily enough. There are methods like map_err and ok_or on Result and Option for most issues that you might encounter.
If you want to find examples that do not always fit Result so well, then you should look at futures and the discussions around futures in the ? rfcs and tracking issues. In other words, your code returns a three+ state enum where what counts as an error may shift depending on usage, so maybe one needs some extra-ergonomic error mapping methods.
I sadly barely get to use
?
, because I find myself not using Result<> as often because it just doesn't fit in. For example, I instead return a struct with asuccess
boolean at one point, or I wanna completely ignore errors the other. There should be a way for?
to detect return values and use some trait to return an error.For example:
Also,
()
return values would implement the trait as well, but return.. well... nothing.If the suggestion sounds stupid to you - sorry for disturbing :(
The text was updated successfully, but these errors were encountered: