-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Avoid naming struct field like trait method #1294
Conversation
Hi @njr0, please let me know if the explanation here is clearer? |
Looks great! Thanks! |
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.
Looks good, just a few ideas for the diagram
src/traits/trait-objects.md
Outdated
: +-----------+-------+ : : | | | '-->| name: "Fido" | : | ||
: : : | | | +---------------+ : | ||
: | capacity | 2 | : : | | | | +-------------+ : | ||
: +-----------+-------+ : : | | | '-->| name: Fido | : |
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 {name: "Fido"}
just to suggest struct-ness and string-ness a bit more?
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.
I see what you mean — though the style on the right is consistent with how the Vec
fields are shown on the left. I've used this "table style" throughout.
Now, I did try to make Fido be "Fido"
, but I didn't manage to escape the "
for the svgbob plugin. The double quote is used to quote special characters for the plugin.
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.
I think I have a nicer and more correct solution: I now show the "Fido"
string as a separate object. This is consistent with that we do in the diagrams for moved strings.
I think it would be good to include a mention of vtable...particularly if there were a sentence explaining what it is in the notes. |
Yeah, that's great...the fact that Anyway, the changes altogether seem like a huge upgrade in comprehensibility to me...especially for people who didn't understand it before coming to this section! |
The `name` struct field was confusing because it was named the same as the trait method. The struct fields are now disjoint from the method names — the fact that there are two separate name spaces is not the point of these slides. I also dropped the zero-sized type, this is also not the main focus here. I also compressed the code a bit to make the unimportant structs take up less space. Fixes #1292.
a6c9254
to
a832013
Compare
I added a link to Wikipedia for the vtable. |
The new diagram should show up on https://google.github.io/comprehensive-rust/traits/trait-objects.html in a few seconds. |
Yes, that's great. 9 lives 😄. |
That's a fantastic result :) |
The
name
struct field was confusing because it was named the same as the trait method.This should clean things up a little. I also compressed the code a bit to make the unimportant structs take up less space.
Fixes #1292.