Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Log implementation for &impl Log and Arc<impl Log> #471

Merged
merged 2 commits into from
Nov 19, 2021

Conversation

piegamesde
Copy link
Contributor

Closes #458. Turns out that Rc<Log> isn't possible because Log: Sync. Other candidates for adding:

  • Cow
  • Option
  • () (this would allow us to get rid of the internal NopLogger)
  • Pin (?)
  • Probably forgot something

src/lib.rs Outdated Show resolved Hide resolved
@KodrAus
Copy link
Contributor

KodrAus commented Nov 15, 2021

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 like Option<T> or () should actually behave.

@piegamesde
Copy link
Contributor Author

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 Pin and Cow open. I'd be in favor of Pin because I don't see any reason not to (the first person coming up with a legitimate use case for Pin<Box<Log>> wins a cookie). For Cow, I don't know. Technically the implementation would simply forward along its Borrow so its good?

@KodrAus
Copy link
Contributor

KodrAus commented Nov 16, 2021

Yeh, there are subtleties in the semantics that I don't think the benefit outweighs for Option or (). Pin and Cow both do seem reasonable. Would you like to include them in this PR or follow-up with another?

@piegamesde
Copy link
Contributor Author

Would you like to include them in this PR or follow-up with another?

Let's do all that make sense right now. I added Pin, but I had to back off Cow because it's Clone constraint on T. This is something that does make little sense for loggers. This is not the first time I've wished for some MaybeOwned in Rust, i.e. a Cow without the "clone" and the "write" part.

For the potential recursion issue mentioned in review, I added #![deny(unconditional_recursion)] instead of a test.

@KodrAus
Copy link
Contributor

KodrAus commented Nov 16, 2021

Ah it looks like we might need to back Pin out too 🙂 It was actually still unstable in 1.31.0

@piegamesde
Copy link
Contributor Author

piegamesde commented Nov 16, 2021

Yes, 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

@KodrAus
Copy link
Contributor

KodrAus commented Nov 17, 2021

Ah unfortunately we can’t really introduce any unconditional dependencies such as rustversion to log. We could do some version detection in the build script, but the best option for now might be to simply roll back Pin.

Closes rust-lang#458. Implements Log for references to loggers, as well as loggers wrapped
in `Arc` or `Pin`. More may be added in the future. Especially, we probably will
want to add a blanket implementation (bounded on `Borrow`) once we have impl
specialization. (Technically, we could probably already do this now, but at the
risk of painting ourselves into a corner.)
Removes the Pin implementation again, because of the MSRV of the crate beeing too low
@piegamesde
Copy link
Contributor Author

piegamesde commented Nov 17, 2021

I removed the Pin implementation 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.

Copy link
Contributor

@KodrAus KodrAus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @piegamesde!

@KodrAus KodrAus merged commit b8571ef into rust-lang:master Nov 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

implement Log on more foreign types
2 participants