feat!(render): render_report can accept more types#371
Open
TheLostLambda wants to merge 2 commits intozkat:mainfrom
Open
feat!(render): render_report can accept more types#371TheLostLambda wants to merge 2 commits intozkat:mainfrom
TheLostLambda wants to merge 2 commits intozkat:mainfrom
Conversation
Brings things in line with best practices as described in "Rust for Rustaceans" when it comes to "Ergonomic Trait Implementations" in Chapter 3. Practically means that people can pass more types to any functions taking either `dyn Diagnostic` or `impl Diagnostic`. BREAKING CHANGE: Added blanket impls may overlap with manual user impls. If these impls are just hacks to achieve the same as the blanket ones do, then they can simply be removed. If the impls for `T` and `&T` differ semantically, then the user would need to employ the newtype pattern to avoid overlap.
You can now pass a `&dyn Diagnostic` (as before), or a `Report` (or `&Report`, `&mut Report`, or `Box<Report>`), or anything else that implements `Diagnostic` to `render_report`. More generally, users can use the `AsDiagnostic` trait wherever they want to write functions that accept either a `Report` or `Diagnostic` — this improves ergonomics in a world where `impl Diagnostic for Report` is impossible. BREAKING CHANGE: Because more types can now be passed to `render_report`, `Report::as_ref()` can get confused about types and inference fails. The solution is removing the `.as_ref()` altogether since `Report` is now a directly accepted type.
Contributor
Author
|
For @zkat , if you think this is a fundamentally worthwhile change, let me know and I can finish writing proper documentation for things here! Additionally, let me know what you think of the changes in #367 when you get the chance! If you don't like them, then I can try to rebase this PR without them! |
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 builds on PR #367! Merging this should be equivalent to merging both!
You can now pass a
&dyn Diagnostic(as before), or aReport(or&Report,&mut Report, orBox<Report>), or anything else that implementsDiagnostictorender_report.More generally, users can use the
AsDiagnostictrait wherever they want to write functions that accept either aReportorDiagnostic— this improves ergonomics in a world whereimpl Diagnostic for Reportis impossible.BREAKING CHANGE: Because more types can now be passed to
render_report,Report::as_ref()can get confused about types, and inference fails. The solution is removing the.as_ref()altogether sinceReportis now a directly accepted type.This would also effectively close #366 (for my purposes, at least), since anything accepting
AsDiagnosticwill work forReportand anything that implementsDiagnostic!BEFORE MERGING: After getting the green light from you, but before merging this, I'll have to properly fill in the documentation for
AsDiagnostic! I don't thinkWOOFandBARKis particularly helpful, but I didn't want to write docs before knowing if you'd be interested in accepting this PR!