Auto merge of #6950 - servo:struct-pattern, r=glennw

Add a comment to explain the struct pattern trick.

https://github.com/servo/servo/issues/6912#issuecomment-127429643

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6950)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-08-04 05:50:27 -06:00
commit 0565df8596

View file

@ -103,6 +103,8 @@ impl<T: HeapSizeOf> HeapSizeOf for Option<T> {
impl HeapSizeOf for url::Url {
fn heap_size_of_children(&self) -> usize {
// Using a struct pattern without `..` rather than `foo.bar` field access
// makes sure this will be updated if a field is added.
let &url::Url { ref scheme, ref scheme_data, ref query, ref fragment } = self;
scheme.heap_size_of_children() +
scheme_data.heap_size_of_children() +
@ -122,6 +124,8 @@ impl HeapSizeOf for url::SchemeData {
impl HeapSizeOf for url::RelativeSchemeData {
fn heap_size_of_children(&self) -> usize {
// Using a struct pattern without `..` rather than `foo.bar` field access
// makes sure this will be updated if a field is added.
let &url::RelativeSchemeData { ref username, ref password, ref host,
ref port, ref default_port, ref path } = self;
username.heap_size_of_children() +