Преглед изворни кода

Merge pull request #38 from gifnksm/master

Add `deriving(Copy)` for `Copy`able structs/enums
Alex Crichton пре 10 година
родитељ
комит
d6d668bf30
3 измењених фајлова са 7 додато и 6 уклоњено
  1. 1 1
      src/bigint.rs
  2. 5 4
      src/complex.rs
  3. 1 1
      src/rational.rs

+ 1 - 1
src/bigint.rs

@@ -857,7 +857,7 @@ fn get_radix_base(radix: uint) -> (DoubleBigDigit, uint) {
 }
 
 /// A Sign is a `BigInt`'s composing element.
-#[deriving(PartialEq, PartialOrd, Eq, Ord, Clone, Show, Encodable, Decodable)]
+#[deriving(PartialEq, PartialOrd, Eq, Ord, Copy, Clone, Show, Encodable, Decodable)]
 pub enum Sign { Minus, NoSign, Plus }
 
 impl Neg<Sign> for Sign {

+ 5 - 4
src/complex.rs

@@ -21,7 +21,7 @@ use {Zero, One, Num};
 // probably doesn't map to C's _Complex correctly.
 
 /// A complex number in Cartesian form.
-#[deriving(PartialEq, Clone, Hash, Encodable, Decodable)]
+#[deriving(PartialEq, Copy, Clone, Hash, Encodable, Decodable)]
 pub struct Complex<T> {
     /// Real portion of the complex number
     pub re: T,
@@ -194,6 +194,7 @@ mod test {
     #![allow(non_upper_case_globals)]
 
     use super::{Complex64, Complex};
+    use std::f64;
     use std::num::Float;
     use std::hash::hash;
 
@@ -283,9 +284,9 @@ mod test {
             assert!((c.arg() - arg).abs() < 1.0e-6)
         }
         test(_1_0i, 0.0);
-        test(_1_1i, 0.25 * Float::pi());
-        test(_neg1_1i, 0.75 * Float::pi());
-        test(_05_05i, 0.25 * Float::pi());
+        test(_1_1i, 0.25 * f64::consts::PI);
+        test(_neg1_1i, 0.75 * f64::consts::PI);
+        test(_05_05i, 0.25 * f64::consts::PI);
     }
 
     #[test]

+ 1 - 1
src/rational.rs

@@ -22,7 +22,7 @@ use bigint::{BigInt, BigUint, Sign};
 use {Num, Signed, Zero, One};
 
 /// Represents the ratio between 2 numbers.
-#[deriving(Clone, Hash, Encodable, Decodable)]
+#[deriving(Copy, Clone, Hash, Encodable, Decodable)]
 #[allow(missing_docs)]
 pub struct Ratio<T> {
     numer: T,