servo: Merge #6950 - Add a comment to explain the struct pattern trick (from servo:struct-pattern); r=glennw

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

Source-Repo: https://github.com/servo/servo
Source-Revision: 0565df859684560b525b0361476d334f79db8474
This commit is contained in:
Simon Sapin 2015-08-04 05:50:27 -06:00
parent 9c986f84a3
commit 4f271271e1

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