diff --git a/Cargo.toml b/Cargo.toml index e3f8690..ebd53a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ license = "MIT / Apache-2.0" [features] default = [] plugins = ["serde", "serde_macros", "heapsize", "heapsize_plugin"] +rustc_stable = [] [dependencies] rustc-serialize = "0.3.2" @@ -26,4 +27,3 @@ optional = true [dependencies.heapsize_plugin] version = "0.1.0" optional = true - diff --git a/src/length.rs b/src/length.rs index 9676b55..0d9f4b2 100644 --- a/src/length.rs +++ b/src/length.rs @@ -9,13 +9,15 @@ //! A one-dimensional length, tagged with its units. use scale_factor::ScaleFactor; -use num::Zero; +use num_lib::Zero; use num_lib::NumCast; #[cfg(feature = "plugins")] use serde::{Deserialize, Deserializer, Serialize, Serializer}; use std::cmp::Ordering; -use std::ops::{Add, AddAssign, Sub, SubAssign, Mul, Div, Neg}; +use std::ops::{Add, Sub, Mul, Div, Neg}; +#[cfg(not(feature="rustc_stable"))] +use std::ops::{AddAssign, SubAssign}; use std::marker::PhantomData; /// A one-dimensional distance, with value represented by `T` and unit of measurement `Unit`. @@ -71,6 +73,7 @@ impl> Add for Length { } // length += length +#[cfg(not(feature="rustc_stable"))] impl> AddAssign for Length { fn add_assign(&mut self, other: Length) { self.0 += other.get(); @@ -86,6 +89,7 @@ impl> Sub> for Length { } // length -= length +#[cfg(not(feature="rustc_stable"))] impl> SubAssign for Length { fn sub_assign(&mut self, other: Length) { self.0 -= other.get(); @@ -160,10 +164,13 @@ impl Ord for Length { fn cmp(&self, other: &Length) -> Ordering { self.get().cmp(&other.get()) } } -impl Zero for Length { +impl Zero for Length { fn zero() -> Length { Length::new(Zero::zero()) } + fn is_zero(&self) -> bool { + self.get().is_zero() + } } #[cfg(test)] diff --git a/src/lib.rs b/src/lib.rs index 392fa11..701074c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,9 +7,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(asm, custom_derive, plugin, repr_simd, zero_one, test)] -#![feature(augmented_assignments)] -#![feature(op_assign_traits)] +#![cfg_attr(not(feature="rustc_stable"), feature(asm, custom_derive, plugin, repr_simd, test))] +#![cfg_attr(not(feature="rustc_stable"), feature(augmented_assignments))] +#![cfg_attr(not(feature="rustc_stable"), feature(op_assign_traits))] #![cfg_attr(feature = "plugins", plugin(heapsize_plugin))] #![cfg_attr(feature = "plugins", plugin(serde_macros))] @@ -25,6 +25,7 @@ extern crate rustc_serialize; extern crate serde; extern crate rand; +#[cfg(not(feature="rustc_stable"))] extern crate test; extern crate num as num_lib; @@ -32,7 +33,9 @@ pub use matrix::Matrix4; pub use matrix2d::Matrix2D; pub use point::{Point2D, Point3D, Point4D}; pub use rect::Rect; +#[cfg(not(feature="rustc_stable"))] pub use side_offsets::SideOffsets2D; +#[cfg(not(feature="rustc_stable"))] pub use side_offsets::SideOffsets2DSimdI32; pub use size::Size2D; @@ -40,9 +43,9 @@ pub mod approxeq; pub mod length; pub mod matrix; pub mod matrix2d; -pub mod num; pub mod point; pub mod rect; pub mod scale_factor; +#[cfg(not(feature="rustc_stable"))] pub mod side_offsets; pub mod size; diff --git a/src/matrix2d.rs b/src/matrix2d.rs index 0a62d94..0a2b097 100644 --- a/src/matrix2d.rs +++ b/src/matrix2d.rs @@ -7,7 +7,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use num::{One, Zero}; +use num_lib::{One, Zero}; use point::Point2D; use rect::Rect; use size::Size2D; diff --git a/src/num.rs b/src/num.rs deleted file mode 100644 index 93c1bd3..0000000 --- a/src/num.rs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2014 The Servo Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. -//! A one-dimensional length, tagged with its units. - -use std::num; - - -pub trait Zero { - fn zero() -> Self; -} - -impl Zero for T { - fn zero() -> T { num::Zero::zero() } -} - -pub trait One { - fn one() -> Self; -} - -impl One for T { - fn one() -> T { num::One::one() } -} - diff --git a/src/point.rs b/src/point.rs index e14aebe..37a0230 100644 --- a/src/point.rs +++ b/src/point.rs @@ -9,8 +9,7 @@ use length::Length; use size::Size2D; -use num::Zero; - +use num_lib::Zero; use num_lib::NumCast; use num_lib::traits; use std::fmt::{self, Formatter}; diff --git a/src/rect.rs b/src/rect.rs index 8b9a15f..e20b3d6 100644 --- a/src/rect.rs +++ b/src/rect.rs @@ -8,7 +8,7 @@ // except according to those terms. use length::Length; -use num::Zero; +use num_lib::Zero; use point::Point2D; use size::Size2D; diff --git a/src/scale_factor.rs b/src/scale_factor.rs index c352b80..272aa6a 100644 --- a/src/scale_factor.rs +++ b/src/scale_factor.rs @@ -8,7 +8,7 @@ // except according to those terms. //! A type-checked scaling factor between units. -use num::One; +use num_lib::One; use num_lib::NumCast; #[cfg(feature = "plugins")] diff --git a/src/side_offsets.rs b/src/side_offsets.rs index ddf5b67..e8d6412 100644 --- a/src/side_offsets.rs +++ b/src/side_offsets.rs @@ -10,7 +10,7 @@ //! A group of side offsets, which correspond to top/left/bottom/right for borders, padding, //! and margins in CSS. -use num::Zero; +use num_lib::Zero; use std::ops::Add; /// A group of side offsets, which correspond to top/left/bottom/right for borders, padding, diff --git a/src/size.rs b/src/size.rs index 4c1ef61..60ae05d 100644 --- a/src/size.rs +++ b/src/size.rs @@ -8,11 +8,11 @@ // except according to those terms. use length::Length; -use num::Zero; +use num_lib::Zero; use num_lib::NumCast; use std::fmt::{self, Formatter}; -use std::ops::{Mul, Div}; +use std::ops::{Add, Mul, Div}; #[derive(Clone, Copy, RustcDecodable, RustcEncodable, PartialEq)] #[cfg_attr(feature = "plugins", derive(HeapSizeOf, Deserialize, Serialize))] @@ -55,13 +55,26 @@ impl Size2D { } } -impl Zero for Size2D { +impl Zero for Size2D { fn zero() -> Size2D { Size2D { width: Zero::zero(), height: Zero::zero(), } } + fn is_zero(&self) -> bool { + self.width.is_zero() && self.height.is_zero() + } +} + +impl + Copy> Add for Size2D { + type Output = Size2D; + fn add(self, rhs: Size2D) -> Size2D { + Size2D { + width: self.width + rhs.width, + height: self.width + rhs.width + } + } } impl, T1: Clone> Mul for Size2D {