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

Commit 442120a

Browse files
author
bors-servo
authored
Auto merge of #89 - servo:ranges, r=emilio
Support Range<T>, RangeFrom<T>, RangeTo<T> and RangeFull <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/heapsize/89) <!-- Reviewable:end -->
2 parents ff5d692 + a57bda1 commit 442120a

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "heapsize"
3-
version = "0.4.1"
3+
version = "0.4.2"
44
authors = [ "The Servo Project Developers" ]
55
description = "Infrastructure for measuring the total runtime size of an object on the heap"
66
license = "MIT/Apache-2.0"

src/lib.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::hash::Hash;
1313
use std::marker::PhantomData;
1414
use std::mem::{size_of, align_of};
1515
use std::net::{Ipv4Addr, Ipv6Addr};
16+
use std::ops::{Range, RangeFrom, RangeFull, RangeTo};
1617
use std::os::raw::c_void;
1718
use std::sync::Arc;
1819
use std::sync::atomic::{AtomicBool, AtomicIsize, AtomicUsize};
@@ -304,6 +305,33 @@ impl<K: HeapSizeOf, V: HeapSizeOf> HeapSizeOf for BTreeMap<K, V> {
304305
}
305306
}
306307

308+
impl<T> HeapSizeOf for Range<T>
309+
where
310+
T: HeapSizeOf,
311+
{
312+
fn heap_size_of_children(&self) -> usize {
313+
self.start.heap_size_of_children() + self.end.heap_size_of_children()
314+
}
315+
}
316+
317+
impl<T> HeapSizeOf for RangeFrom<T>
318+
where
319+
T: HeapSizeOf,
320+
{
321+
fn heap_size_of_children(&self) -> usize {
322+
self.start.heap_size_of_children()
323+
}
324+
}
325+
326+
impl<T> HeapSizeOf for RangeTo<T>
327+
where
328+
T: HeapSizeOf,
329+
{
330+
fn heap_size_of_children(&self) -> usize {
331+
self.end.heap_size_of_children()
332+
}
333+
}
334+
307335
/// For use on types defined in external crates
308336
/// with known heap sizes.
309337
#[macro_export]
@@ -335,4 +363,4 @@ known_heap_size!(0, u8, u16, u32, u64, usize);
335363
known_heap_size!(0, i8, i16, i32, i64, isize);
336364
known_heap_size!(0, bool, f32, f64);
337365
known_heap_size!(0, AtomicBool, AtomicIsize, AtomicUsize);
338-
known_heap_size!(0, Ipv4Addr, Ipv6Addr);
366+
known_heap_size!(0, Ipv4Addr, Ipv6Addr, RangeFull);

0 commit comments

Comments
 (0)