Add a comment to explain the struct pattern trick.

https://github.com/servo/servo/issues/6912#issuecomment-127429643
This commit is contained in:
Simon Sapin 2015-08-04 07:28:53 +02:00
parent 84e25befdd
commit 0f0de57936

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() +