Closed demurgos closed 10 months ago
This is brilliant!! I'm not the greatest with traditional macros, so I'm not 100% sure about compatibility either.
I will rebase this to be compatible with the last PR.
Thank you for reviewing and merging my changes
This commit adds support for error references for the
#
error formatter from thekv
macro. If the passed error is an owned error value it usesErrorValue
; otherwise if it can be dereferenced into an error then it usesErrorRef
.The way to detect if the value implements
Error
directly or if it's an error reference is based on auto-deref coercion as described in the following articles:I believe it to be fully backwards compatible with existing uses of
#
. This provides a short-hand for theErrorRef
wrapper in most common cases. However, it does not support temporary lifetime extension.This means that the following example needs to introduce a temporary binding to use the shorthand syntax:
In practice, this use case is not an issue. Such a temporary can instead be passed by value (the reference is useless) through
ErrorValue
. There are discussions in Zulip to support explicit lifetime extensions and support this use case in the future.Make sure to:
This is a follow up to https://github.com/slog-rs/slog/pull/327 to add support for the macro shorthand
#
. I sent it in its own PR as the logic is more complex and I don't want to block the simple error reference wrapper because of the macro logic. Commit with macro support