Merged
Conversation
Collaborator
|
Thanks for the PR @divergentdave! It looks like we're accumulating a bit of logic in this method so maybe it's time to refactor it a bit into something more manageable. I was thinking we could just inline the write call into the places where we have a let print = |formatter, record| {
let _ = (self.format)(&mut formatter, record)
.and_then(|_| formatter.print(&self.writer));
formatter.clear();
}
let printed = FORMATTER.try_with(|tl_buf| {
match tl_buf.try_borrow_mut() {
// There are no active borrows of the buffer
Ok(ref mut tl_buf) => match tl_buf {
// We have a previously set formatter
Some(ref mut formatter) => {
if formatter.write_style() != self.writer.write_style() {
*formatter = Formatter::new(&self.writer)
}
print(formatter, record);
},
// We don't have a previously set formatter
None => {
let mut formatter = Formatter::new(&self.writer);
print(formatter, record);
*tl_buf = Some(formatter);
}
}
// There's already an active borrow of the buffer
Err(_) => {
print(&mut Formatter::new(&self.writer), record);
}
}
}).is_ok();
if !printed {
print(&mut Formatter::new(&self.writer), record);
}What do you think? |
Contributor
Author
|
Sounds good, I'll split that out |
KodrAus
approved these changes
Oct 17, 2019
Collaborator
KodrAus
left a comment
There was a problem hiding this comment.
Thanks @divergentdave! This looks good to me
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR provides a failing test to reproduce the issue described in #145, and fixes the issue as described by handling the AccessError.