Closed kmsquire closed 4 years ago
Merging #17 into master will not change coverage. The diff coverage is
100%
.
@@ Coverage Diff @@
## master #17 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 1 1
Lines 29 38 +9
=====================================
+ Hits 29 38 +9
Impacted Files | Coverage Δ | |
---|---|---|
src/ResultTypes.jl | 100% <100%> (ø) |
:arrow_up: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update 24e0aa7...d488e1c. Read the comment docs.
Looks good, but here's an additional suggestion:
What about an optional second argument that is a replacement exception to return? This will prevent people from having to necessarily pirate exception conversions in some cases, while still adding the convenience of the compact early return syntax.
Okay, @iamed2, I added a version which takes an error as the second argument. Let me know what you think and if you want any changes.
I just realized that !
is the syntax for macro calls in rust (I've only dabbled in the language). Since we're not modifying our arguments here, I'm going to change this to @try
.
... which of course doesn't work because try
is a keyword... ( sigh )
Actually, I just learned that it is possible to define @try
:
https://discourse.julialang.org/t/using-reserved-words-syntax-try-as-macro-names/34063
Will push that change again.
Ready for re-review.
Sorry, forgot that I was using an autoformatter. Will fix.
Should be good to go!
Thanks!
x
is an error, otherwise unwrapsx
This mimics the behavior of the macro of the same name in Rust.
Rust has actually moved away from this macro, now adding
?
to the end ofResult
types instead. That option isn't available to Julia (unless, perhaps, Julia moves towards usingResultTypes
by default.)I really wanted to call this
@?
, but question marks are not valid identifiers (they're syntax). I also tried@/
(a?
without pressing shift, on US keyboards at least). But that looked funny, so I went with precedence.One other Rust-like behavior that this assumes is that exceptions higher in the stack will be converted to different exceptions as the stack unwinds. This is not common in Julia code (because exceptions are usually thrown, so there's little need to
convert
them). An additionalResult
convert
method was added to make this easier, but users will still need to addconvert
methods for converting between their own exception types.Example from the tests: