|
I'd write it more like:code:
QuantumNinja fucked around with this message at 06:13 on Jul 28, 2016 |
# ¿ Jul 28, 2016 06:10 |
|
|
# ¿ May 3, 2024 08:59 |
|
taqueso posted:I don't want to panic inside my library for a minor error like this. I'm trying to pass the results all the way out to the API boundary so the calling app can see & handle the errors. I considered using Option here, but didn't use it for 2 reasons - I read somewhere that it was bad form to use None to indicate an error condition, and also so I don't have to convert the Option to a Result in the calling functions. This is pretty analogous to std's use of None when popping from a collection, so it is mostly for the second reason. I agree that panic! is probably too much. But I wasn't advocating None as Error, I was advocating None as the unit result, where you only get something back if you have an error. For the sort of thing you seem to have here, though, I agree that following the Option conventions of std::Vec is probably a good best-practices guideline. Vanadium posted:Result<(), T> is a legit pattern. You see it in std::fmt and the serialzied, and a few other places, but it's never carried very far in those APIs. taqueso's snippet sort of implies that it's going to carry a Result<(), T> through a few layers to "propagate the error", though, and that's going to induce a nasty ok_or chain all the way up the callstack.
|
# ¿ Jul 28, 2016 19:03 |