From 3ccb4bd6c5cfaa8287fb19bd2c4ebbdfb9d77025 Mon Sep 17 00:00:00 2001 From: Gustorn Date: Wed, 19 Aug 2015 19:11:55 +0200 Subject: [PATCH] Added Sized trait bound for traits that requite it See rust-lang/rfcs#1214 --- src/traits.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/traits.rs b/src/traits.rs index 12d5cdf..3cf0268 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -212,7 +212,7 @@ float_trait_impl!(Num for f32 f64); /// This trait can be automatically be derived using `#[deriving(Zero)]` /// attribute. If you choose to use this, make sure that the laws outlined in /// the documentation for `Zero::zero` still hold. -pub trait Zero: Add { +pub trait Zero: Sized + Add { /// Returns the additive identity element of `Self`, `0`. /// /// # Laws @@ -262,7 +262,7 @@ zero_impl!(f32, 0.0f32); zero_impl!(f64, 0.0f64); /// Defines a multiplicative identity element for `Self`. -pub trait One: Mul { +pub trait One: Sized + Mul { /// Returns the multiplicative identity element of `Self`, `1`. /// /// # Laws @@ -306,7 +306,7 @@ one_impl!(f32, 1.0f32); one_impl!(f64, 1.0f64); /// Useful functions for signed numbers (i.e. numbers that can be negative). -pub trait Signed: Num + Neg { +pub trait Signed: Sized + Num + Neg { /// Computes the absolute value. /// /// For `f32` and `f64`, `NaN` will be returned if the number is `NaN`. @@ -532,7 +532,7 @@ impl Saturating for T /// Performs addition that returns `None` instead of wrapping around on /// overflow. -pub trait CheckedAdd: Add { +pub trait CheckedAdd: Sized + Add { /// Adds two numbers, checking for overflow. If overflow happens, `None` is /// returned. fn checked_add(&self, v: &Self) -> Option; @@ -562,7 +562,7 @@ checked_impl!(CheckedAdd, checked_add, i64); checked_impl!(CheckedAdd, checked_add, isize); /// Performs subtraction that returns `None` instead of wrapping around on underflow. -pub trait CheckedSub: Sub { +pub trait CheckedSub: Sized + Sub { /// Subtracts two numbers, checking for underflow. If underflow happens, /// `None` is returned. fn checked_sub(&self, v: &Self) -> Option; @@ -582,7 +582,7 @@ checked_impl!(CheckedSub, checked_sub, isize); /// Performs multiplication that returns `None` instead of wrapping around on underflow or /// overflow. -pub trait CheckedMul: Mul { +pub trait CheckedMul: Sized + Mul { /// Multiplies two numbers, checking for underflow or overflow. If underflow /// or overflow happens, `None` is returned. fn checked_mul(&self, v: &Self) -> Option; @@ -602,7 +602,7 @@ checked_impl!(CheckedMul, checked_mul, isize); /// Performs division that returns `None` instead of panicking on division by zero and instead of /// wrapping around on underflow and overflow. -pub trait CheckedDiv: Div { +pub trait CheckedDiv: Sized + Div { /// Divides two numbers, checking for underflow, overflow and division by /// zero. If any of that happens, `None` is returned. fn checked_div(&self, v: &Self) -> Option; @@ -1303,7 +1303,7 @@ pub fn cast(n: T) -> Option { } /// An interface for casting between machine scalars. -pub trait NumCast: ToPrimitive { +pub trait NumCast: Sized + ToPrimitive { /// Creates a number from another value that can be converted into /// a primitive via the `ToPrimitive` trait. fn from(n: T) -> Option;