Skip to content
This repository was archived by the owner on Jul 10, 2023. It is now read-only.

Commit e9bc1a5

Browse files
author
bors-servo
committed
Auto merge of #15 - notriddle:master, r=Manishearth
Add support for `Cow`. Hyper uses it. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/heapsize/15) <!-- Reviewable:end -->
2 parents 376933f + 098fc1e commit e9bc1a5

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
extern crate libc;
1010

1111
use libc::{c_void, size_t};
12+
use std::borrow::Cow;
1213
use std::cell::{Cell, RefCell};
1314
use std::collections::{HashMap, LinkedList};
1415
#[cfg(feature = "unstable")]
@@ -89,6 +90,15 @@ impl<T: HeapSizeOf> HeapSizeOf for Option<T> {
8990
}
9091
}
9192

93+
impl<'a, B: ?Sized + ToOwned> HeapSizeOf for Cow<'a, B> where B::Owned: HeapSizeOf {
94+
fn heap_size_of_children(&self) -> usize {
95+
match *self {
96+
Cow::Borrowed(_) => 0,
97+
Cow::Owned(ref b) => b.heap_size_of_children(),
98+
}
99+
}
100+
}
101+
92102
impl<T: HeapSizeOf, U: HeapSizeOf> HeapSizeOf for (T, U) {
93103
fn heap_size_of_children(&self) -> usize {
94104
self.0.heap_size_of_children() + self.1.heap_size_of_children()

0 commit comments

Comments
 (0)