You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
rust-url being an external crate makes it hard to derive HeapSizeOf, but implementing manually in mem.rs should be doable as all Url fields are public. To make sure this impl is and stays correct, use struct patterns rather than foo.bar field access:
Why do struct patterns ensure forward compatability here? Also what if more public fields are added? Won't the struct pattern then fail but direct field access have been fine?
That’s the point: if a future rust-url version adds a new field, an exhaustive struct pattern (without ..) will fail to build rather then silently fail to measure some data. This build failure will force us to update the measuring code to make it correct again.
Activity
SimonSapin commentedon Aug 3, 2015
rust-url being an external crate makes it hard to derive
HeapSizeOf, but implementing manually inmem.rsshould be doable as allUrlfields are public. To make sure this impl is and stays correct, use struct patterns rather thanfoo.barfield access:metajack commentedon Aug 3, 2015
Why do struct patterns ensure forward compatability here? Also what if more public fields are added? Won't the struct pattern then fail but direct field access have been fine?
SimonSapin commentedon Aug 3, 2015
That’s the point: if a future rust-url version adds a new field, an exhaustive struct pattern (without
..) will fail to build rather then silently fail to measure some data. This build failure will force us to update the measuring code to make it correct again.nnethercote commentedon Aug 3, 2015
That's a neat trick.
nnethercote commentedon Aug 3, 2015
...and a trick that arguably deserves a comment so some eager beaver doesn't rewrite the code in the future?
Auto merge of #6932 - boghison:memrs, r=SimonSapin
Add a comment to explain the struct pattern trick.
Add a comment to explain the struct pattern trick.
Auto merge of #6950 - servo:struct-pattern, r=glennw
servo: Merge #6950 - Add a comment to explain the struct pattern tric…
servo: Merge #6950 - Add a comment to explain the struct pattern tric…
servo: Merge #6950 - Add a comment to explain the struct pattern tric…
servo: Merge #6950 - Add a comment to explain the struct pattern tric…