Allow with_frame
to be called from inside a loop
#5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Thank you for providing a Rollbar client library for Rust! This is a very useful thing to have.
We use the
error-trace
library, which provides backtraces for wherethe original error occurred. We wanted to pass these backtraces to
rollbar
. But to do this, we needed to callwith_frame
in a loop,and this failed as follows:
The problem occurs because of a subtle lifetime issue in the function
declaration:
Here,
Self
refers to the typeReportErrorBuilder<'a>
, which containsthe lifetime
'a
. But the thewith_frame
function uses a mutablereference
&'a mut self
, which also includes'a
. This says that thereference to
ReportErrorBuilder
has the same lifetime as theReportErrorBuilder
itself, which makes it impossible to use thefunction anywhere except in a "fluent" call chain:
But if we change the signature to:
...then Rust will automatically generate a new lifetime (call it
'b
)for the
&mut
reference. This will make everything work nicely. Inthis case, Rust's defaults do exactly what you want.
You may also want to apply a similar fix to
with_backtrace
, but Ihaven't looked at that yet.