Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HeapSizeOf implementation. #99

Merged
merged 3 commits into from
Aug 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,22 @@ documentation = "http://doc.servo.org/euclid/"
repository = "https://github.com/servo/euclid"
license = "MIT / Apache-2.0"

[features]
heap_size = [ "heapsize", "heapsize_plugin" ]

[dependencies]
rustc-serialize = "0.3.2"
rand = "0.3.7"
num = "0.1.24"
log = "0.3.1"
serde = "*"
serde_macros = "*"

[dependencies.heapsize]
version = "0.1.2"
optional = true

[dependencies.heapsize_plugin]
version = "0.0.1"
optional = true

3 changes: 3 additions & 0 deletions src/length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ use std::marker::PhantomData;
///
/// You can multiply a Length by a `scale_factor::ScaleFactor` to convert it from one unit to
/// another. See the ScaleFactor docs for an example.
// Uncomment the derive, and remove the macro call, once heapsize gets
// PhantomData<T> support.
#[derive(Copy, RustcDecodable, RustcEncodable, Debug)]
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
pub struct Length<Unit, T>(pub T, PhantomData<Unit>);

impl<Unit,T> Deserialize for Length<Unit,T> where T: Deserialize {
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@

#![plugin(serde_macros)]

#![cfg_attr(feature = "heap_size", plugin(heapsize_plugin))]

#[cfg(feature = "heap_size")]
#[macro_use]
extern crate heapsize;

#[macro_use]
extern crate log;
extern crate rustc_serialize;
Expand Down
1 change: 1 addition & 0 deletions src/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use point::{Point2D, Point4D};


#[derive(Debug, Copy, Clone, PartialEq, Deserialize, Serialize)]
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
pub struct Matrix4 {
pub m11: f32, pub m12: f32, pub m13: f32, pub m14: f32,
pub m21: f32, pub m22: f32, pub m23: f32, pub m24: f32,
Expand Down
1 change: 1 addition & 0 deletions src/matrix2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use size::Size2D;
use std::ops::{Add, Mul, Sub};

#[derive(Clone, Copy, Deserialize, Serialize)]
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
pub struct Matrix2D<T> {
m11: T, m12: T,
m21: T, m22: T,
Expand Down
3 changes: 3 additions & 0 deletions src/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::fmt::{self, Formatter};
use std::ops::{Add, Neg, Mul, Sub, Div};

#[derive(Clone, Copy, RustcDecodable, RustcEncodable, Eq, Hash, PartialEq, Deserialize, Serialize)]
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
pub struct Point2D<T> {
pub x: T,
pub y: T
Expand Down Expand Up @@ -139,6 +140,7 @@ impl<Unit, T: NumCast + Clone> Point2D<Length<Unit, T>> {
}

#[derive(Clone, Copy, RustcDecodable, RustcEncodable, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
pub struct Point3D<T> {
pub x: T,
pub y: T,
Expand Down Expand Up @@ -198,6 +200,7 @@ impl <T:Clone + Neg<Output=T>> Neg for Point3D<T> {
}

#[derive(Clone, Copy, RustcDecodable, RustcEncodable, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
pub struct Point4D<T> {
pub x: T,
pub y: T,
Expand Down
1 change: 1 addition & 0 deletions src/rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::fmt::{self, Formatter};
use std::ops::{Add, Sub, Mul, Div};

#[derive(Clone, Copy, RustcDecodable, RustcEncodable, PartialEq, Deserialize, Serialize)]
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
pub struct Rect<T> {
pub origin: Point2D<T>,
pub size: Size2D<T>,
Expand Down
4 changes: 4 additions & 0 deletions src/scale_factor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ use std::marker::PhantomData;
/// let one_foot: Length<Inch, f32> = Length::new(12.0);
/// let one_foot_in_mm: Length<Mm, f32> = one_foot * mm_per_inch;
/// ```
// Uncomment the derive, and remove the macro call, once heapsize gets
// PhantomData<T> support.
#[derive(Copy, RustcDecodable, RustcEncodable, Debug)]
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
pub struct ScaleFactor<Src, Dst, T>(pub T, PhantomData<(Src, Dst)>);


impl<Src,Dst,T> Deserialize for ScaleFactor<Src,Dst,T> where T: Deserialize {
fn deserialize<D>(deserializer: &mut D) -> Result<ScaleFactor<Src,Dst,T>,D::Error>
where D: Deserializer {
Expand Down
2 changes: 2 additions & 0 deletions src/side_offsets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::ops::Add;
/// A group of side offsets, which correspond to top/left/bottom/right for borders, padding,
/// and margins in CSS.
#[derive(Clone, Copy, PartialEq, Debug, Deserialize, Serialize)]
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
pub struct SideOffsets2D<T> {
pub top: T,
pub right: T,
Expand Down Expand Up @@ -76,6 +77,7 @@ impl<T: Zero> SideOffsets2D<T> {
/// A SIMD enabled version of SideOffsets2D specialized for i32.
#[derive(Clone, Copy, PartialEq)]
#[simd]
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
pub struct SideOffsets2DSimdI32 {
pub top: i32,
pub bottom: i32,
Expand Down
1 change: 1 addition & 0 deletions src/size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use std::fmt::{self, Formatter};
use std::ops::{Mul, Div};

#[derive(Clone, Copy, RustcDecodable, RustcEncodable, PartialEq, Deserialize, Serialize)]
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
pub struct Size2D<T> {
pub width: T,
pub height: T
Expand Down