Skip to content

Commit

Permalink
Add HeapSizeOf support.
Browse files Browse the repository at this point in the history
  • Loading branch information
notriddle committed Aug 14, 2015
1 parent cbd1602 commit 2550ee7
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,23 @@ 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.1"
path = "../heapsize"
optional = true

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

1 change: 1 addition & 0 deletions src/length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ 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.
#[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
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

#![plugin(serde_macros)]

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

#[cfg(feature = "heap_size")]
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
1 change: 1 addition & 0 deletions src/scale_factor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use std::marker::PhantomData;
/// let one_foot_in_mm: Length<Mm, f32> = one_foot * mm_per_inch;
/// ```
#[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 {
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

0 comments on commit 2550ee7

Please sign in to comment.