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
impl Debug for Readers #390
Conversation
Thanks! I agree that there should be an easy way to print out a textual representation of a reader. |
Something that I considered was implementing LabelledGeneric where Readers' implementations produce an Should I separate out changing the getters' self parameter into a separate PR? |
capnpc/src/codegen_types.rs
Outdated
@@ -130,6 +131,13 @@ impl<'a> RustNodeInfo for node::Reader<'a> { | |||
.collect::<Vec<String>>() | |||
.join(", ") | |||
+ " "); | |||
let where_clause_with_debug = "where ".to_string() |
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.
Maybe instead of doing this we could add the Debug
bound in the definition of the Owned
trait.
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.
Adding a Debug bound to the Owned trait required adding more constraints to a lot of other Readers. I've put this in a separate commit - which way do you think is cleaner?
How did changing the self parameter help you? My understanding is that you should be able to insert |
The |
That being said, it appears that changing the generated reborrow function to have a signature |
Ah, the problem is that generic readers were not |
Yep, that was the issue. I removed the &self change. |
I've made significant progress on #392, and I'm now convinced that approach is going to work. It should generalize to Builders too. My plan is to get it into a releasable state and to ship it (including |
Closing in favor of #392. |
This generates implementations of Debug for Readers for easier debugging. (I did not implement it for Builders because of some messy lifetimes issues.)
To make this work, I changed the getters on Readers to borrow instead of consume (see: #241 (comment)). This should be a safe and backwards-compatible change but I am not completely sure. I had to do this because reborrow throws away lifetime information that is necessary for the Debug implementations to pass the borrow checker.