-
Notifications
You must be signed in to change notification settings - Fork 19
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
implicitly require fmt::Display on all type parameters unless overridden #28
implicitly require fmt::Display on all type parameters unless overridden #28
Conversation
Realized the "shoddy workaround" would break existing code, so was thinking about changing this to not adding the |
Done! |
d23ecba
to
efa8f4d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is amazing Danny, thank you for this PR, particularly the comments which made reviewing this a breeze.
I love this crate!!
This brings me joy 😄
Hey @cosmicexplorer, are you still interested in landing this change? |
efa8f4d
to
92571d2
Compare
Yes! I ended up moving across the country very soon after providing this first draft and there's absolutely no reason I should have put this off as it remains useful to me! Upon finally mustering the courage to check over your comments just now I'm seeing that I need to think a little harder about Sorry for making this drag out so long, I will respond to the rest of your comments by tomorrow. Thanks for your patience! |
0fdbb0a
to
3b74bb0
Compare
No problem at all, take your time Danny. |
2412bec
to
f6433f4
Compare
Gonna bump the MSRV to 1.45 to make |
1286462
to
cf6a9f7
Compare
- add doctest and FAQ - clarify that if fields impl Debug, they don't need to impl Display - make pedantic spelling change - add note on how destructuring is used for format strings - clarify the mechanism of adding Display only when otherwise unconstrained and add TODO
cf6a9f7
to
e2cb86f
Compare
Thank you again! |
Problem
I love this crate!! I wanted to use it on an enum struct with a type parameter but I ran into the Problem in #19!
Solution
Adding the
Display
implI didn't take a look at
derive_more
as mentioned in #19; instead, I noticed that we are not modifying struct or enum definitions to implicitly requirefmt::Display
, but that our ownfmt::Display
impl was unable to infer it for arguments which depended on a type parameter. For example, the following fails to compile right now:Producing:
So I basically just tried to hack it so that
where E: core::fmt::Display
would be written where we generate ourDisplay
impl.Result
The benefit of this change is that it lets an enum deriving
displaydoc::Display
become usable as a generic parameterized result type for a generic method without making that enum have to carry thewhere _: Display
, as demonstrated below. This behavior is very similar to the built-in#[derive(...)]
macros forDebug
,PartialEq
,Hash
, etc: