about summary refs log tree commit diff
path: root/src/libstd/num/mod.rs
diff options
context:
space:
mode:
authorBrendan Zabarauskas <bjzaba@yahoo.com.au>2014-01-15 11:32:04 +1100
committerBrendan Zabarauskas <bjzaba@yahoo.com.au>2014-01-16 11:51:33 +1100
commit1dd6906db2e6749bc3f113068e7493070b276feb (patch)
treebf4ce1a1c06bceadb28c70a4d522c9a5b9921738 /src/libstd/num/mod.rs
parent149fc76698318f8f7cdfaa37a818e347721764e7 (diff)
downloadrust-1dd6906db2e6749bc3f113068e7493070b276feb.tar.gz
rust-1dd6906db2e6749bc3f113068e7493070b276feb.zip
Merge Bitwise and BitCount traits and remove from prelude, along with Bounded
One less trait in std::num, and three less exported in the prelude.
Diffstat (limited to 'src/libstd/num/mod.rs')
-rw-r--r--src/libstd/num/mod.rs31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs
index 2bf3158e6b4..05f21c7d448 100644
--- a/src/libstd/num/mod.rs
+++ b/src/libstd/num/mod.rs
@@ -324,21 +324,27 @@ pub trait Real: Signed
 /// Inverse hyperbolic tangent function.
 #[inline(always)] pub fn atanh<T: Real>(value: T) -> T { value.atanh() }
 
-/// Collects the bitwise operators under one trait.
-pub trait Bitwise: Not<Self>
+pub trait Bounded {
+    // FIXME (#5527): These should be associated constants
+    fn min_value() -> Self;
+    fn max_value() -> Self;
+}
+
+/// Numbers with a fixed binary representation.
+pub trait Bitwise: Bounded
+                 + Not<Self>
                  + BitAnd<Self,Self>
                  + BitOr<Self,Self>
                  + BitXor<Self,Self>
                  + Shl<Self,Self>
-                 + Shr<Self,Self> {}
-
-/// A trait for common counting operations on bits.
-pub trait BitCount {
+                 + Shr<Self,Self> {
     /// Returns the number of bits set in the number.
     ///
     /// # Example
     ///
     /// ```rust
+    /// use std::num::Bitwise;
+    ///
     /// let n = 0b0101000u16;
     /// assert_eq!(n.population_count(), 2);
     /// ```
@@ -348,6 +354,8 @@ pub trait BitCount {
     /// # Example
     ///
     /// ```rust
+    /// use std::num::Bitwise;
+    ///
     /// let n = 0b0101000u16;
     /// assert_eq!(n.leading_zeros(), 10);
     /// ```
@@ -357,18 +365,14 @@ pub trait BitCount {
     /// # Example
     ///
     /// ```rust
+    /// use std::num::Bitwise;
+    ///
     /// let n = 0b0101000u16;
     /// assert_eq!(n.trailing_zeros(), 3);
     /// ```
     fn trailing_zeros(&self) -> Self;
 }
 
-pub trait Bounded {
-    // FIXME (#5527): These should be associated constants
-    fn min_value() -> Self;
-    fn max_value() -> Self;
-}
-
 /// Specifies the available operations common to all of Rust's core numeric primitives.
 /// These may not always make sense from a purely mathematical point of view, but
 /// may be useful for systems programming.
@@ -394,8 +398,7 @@ pub trait Primitive: Clone
 /// A collection of traits relevant to primitive signed and unsigned integers
 pub trait Int: Integer
              + Primitive
-             + Bitwise
-             + BitCount {}
+             + Bitwise {}
 
 /// Used for representing the classification of floating point numbers
 #[deriving(Eq)]