Add Log implementation for &impl Log and Arc<impl Log> #471
No reviewers
Labels
No labels
bug
duplicate
easy
enhancement
help wanted
invalid
question
rfc
structured-logging
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-rust-lang/log!471
Loading…
Reference in a new issue
No description provided.
Delete branch "master"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #458. Turns out that
Rc<Log>isn't possible becauseLog: Sync. Other candidates for adding:CowOption()(this would allow us to get rid of the internalNopLogger)Pin(?)@ -1250,6 +1250,22 @@ impl Log for NopLogger {fn flush(&self) {}Normally I'd write something like
(**self).enabled(metadata)when forwarding implementations on references. I just thought I'd check to make sure this isn't a possible infinite recursion 🙂@ -1250,6 +1250,22 @@ impl Log for NopLogger {fn flush(&self) {}I'd forgotten the * and I had a warning, then I added it and the warning went away so we should be good. I could add a test that would otherwise trigger the infinite recursion if you like.
Thanks @piegamesde! I think this is a great starting point. I think ideally we'd stick to implementations that can unconditionally forward to another implementation, like
Box<T>,Arc<T>,&T. Just to avoid any possible confusion over how something likeOption<T>or()should actually behave.I'd argue that the intent for
Option<T>is rather clear and for()more or less as well. But I agree that this can be overdone (looking at you, Haskell) and one has to draw the line somewhere.This still leaves
PinandCowopen. I'd be in favor ofPinbecause I don't see any reason not to (the first person coming up with a legitimate use case forPin<Box<Log>>wins a cookie). ForCow, I don't know. Technically the implementation would simply forward along itsBorrowso its good?Yeh, there are subtleties in the semantics that I don't think the benefit outweighs for
Optionor().PinandCowboth do seem reasonable. Would you like to include them in this PR or follow-up with another?@ -1250,6 +1250,22 @@ impl Log for NopLogger {fn flush(&self) {}The more tests the merrier!
Let's do all that make sense right now. I added
Pin, but I had to back offCowbecause it'sCloneconstraint onT. This is something that does make little sense for loggers. This is not the first time I've wished for someMaybeOwnedin Rust, i.e. aCowwithout the "clone" and the "write" part.For the potential recursion issue mentioned in review, I added
#![deny(unconditional_recursion)]instead of a test.Ah it looks like we might need to back
Pinout too 🙂 It was actually still unstable in 1.31.0Yes, I've seen the CI fail too. Is there a way to feature guard this only for newer Rust versions? Edit: found it: https://github.com/dtolnay/rustversion#use-cases
Ah unfortunately we can’t really introduce any unconditional dependencies such as
rustversiontolog. We could do some version detection in the build script, but the best option for now might be to simply roll backPin.I removed the
Pinimplementation in a second commit so that you can simply revert it after the next MSRV bump. Feel free to squash it if you prefer it that way.Thanks for working on this @piegamesde!