summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-07-09 15:13:40 -0700
committerbors <bors@rust-lang.org>2013-07-09 15:13:40 -0700
commit137d1fb210a844a76f89d7355a1aaf9f7a88af33 (patch)
tree79aa81625da93344be55a61eb80c8d215dd4a808 /src/libstd
parente388a80c234d628c4d1fab77dc3e3f2c04cbefc5 (diff)
parent31114acdd7da8f2826558b11adea96d1c561aabd (diff)
downloadrust-137d1fb210a844a76f89d7355a1aaf9f7a88af33.tar.gz
rust-137d1fb210a844a76f89d7355a1aaf9f7a88af33.zip
auto merge of #7657 : thestinger/rust/rollup, r=thestinger
d3be8ab r=brson
05eb3cf r=thestinger
c80f4e1 r=huonw
8c27af1 r=huonw
0eee0b6 r=cmr
ea2756a r=thestinger
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/bool.rs25
-rw-r--r--src/libstd/option.rs50
-rw-r--r--src/libstd/rt/global_heap.rs4
-rw-r--r--src/libstd/vec.rs2
4 files changed, 78 insertions, 3 deletions
diff --git a/src/libstd/bool.rs b/src/libstd/bool.rs
index b0b586df4b5..126650981cd 100644
--- a/src/libstd/bool.rs
+++ b/src/libstd/bool.rs
@@ -19,6 +19,8 @@ A quick summary:
 Implementations of the following traits:
 
 * `FromStr`
+* `ToStr`
+* `Not`
 * `Ord`
 * `TotalOrd`
 * `Eq`
@@ -36,6 +38,8 @@ Finally, some inquries into the nature of truth: `is_true` and `is_false`.
 
 #[cfg(not(test))]
 use cmp::{Eq, Ord, TotalOrd, Ordering};
+#[cfg(not(test))]
+use ops::Not;
 use option::{None, Option, Some};
 use from_str::FromStr;
 use to_str::ToStr;
@@ -254,6 +258,27 @@ pub fn all_values(blk: &fn(v: bool)) {
 #[inline]
 pub fn to_bit(v: bool) -> u8 { if v { 1u8 } else { 0u8 } }
 
+/**
+* The logical complement of a boolean value.
+*
+* # Examples
+*
+* ~~~rust
+* rusti> !true
+* false
+* ~~~
+*
+* ~~~rust
+* rusti> !false
+* true
+* ~~~
+*/
+#[cfg(not(test))]
+impl Not<bool> for bool {
+    #[inline]
+    fn not(&self) -> bool { !*self }
+}
+
 #[cfg(not(test))]
 impl Ord for bool {
     #[inline]
diff --git a/src/libstd/option.rs b/src/libstd/option.rs
index fb9962f8a44..222952a6dc1 100644
--- a/src/libstd/option.rs
+++ b/src/libstd/option.rs
@@ -379,6 +379,13 @@ impl<'self, A> Iterator<&'self A> for OptionIterator<'self, A> {
     fn next(&mut self) -> Option<&'self A> {
         util::replace(&mut self.opt, None)
     }
+
+    fn size_hint(&self) -> (uint, Option<uint>) {
+        match self.opt {
+            Some(_) => (1, Some(1)),
+            None => (0, Some(0)),
+        }
+    }
 }
 
 /// Mutable iterator over an `Option<A>`
@@ -390,6 +397,13 @@ impl<'self, A> Iterator<&'self mut A> for OptionMutIterator<'self, A> {
     fn next(&mut self) -> Option<&'self mut A> {
         util::replace(&mut self.opt, None)
     }
+
+    fn size_hint(&self) -> (uint, Option<uint>) {
+        match self.opt {
+            Some(_) => (1, Some(1)),
+            None => (0, Some(0)),
+        }
+    }
 }
 
 #[test]
@@ -487,3 +501,39 @@ fn test_filtered() {
     assert_eq!(some_stuff.get(), 42);
     assert!(modified_stuff.is_none());
 }
+
+#[test]
+fn test_iter() {
+    let val = 5;
+
+    let x = Some(val);
+    let mut it = x.iter();
+
+    assert_eq!(it.size_hint(), (1, Some(1)));
+    assert_eq!(it.next(), Some(&val));
+    assert_eq!(it.size_hint(), (0, Some(0)));
+    assert!(it.next().is_none());
+}
+
+#[test]
+fn test_mut_iter() {
+    let val = 5;
+    let new_val = 11;
+
+    let mut x = Some(val);
+    let mut it = x.mut_iter();
+
+    assert_eq!(it.size_hint(), (1, Some(1)));
+
+    match it.next() {
+        Some(interior) => {
+            assert_eq!(*interior, val);
+            *interior = new_val;
+            assert_eq!(x, Some(new_val));
+        }
+        None => assert!(false),
+    }
+
+    assert_eq!(it.size_hint(), (0, Some(0)));
+    assert!(it.next().is_none());
+}
diff --git a/src/libstd/rt/global_heap.rs b/src/libstd/rt/global_heap.rs
index 54deb8924f5..ef89b8de454 100644
--- a/src/libstd/rt/global_heap.rs
+++ b/src/libstd/rt/global_heap.rs
@@ -76,11 +76,11 @@ pub unsafe fn exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
     box as *c_char
 }
 
-// FIXME #4942: Make these signatures agree with exchange_alloc's signatures
+/// The allocator for unique pointers without contained managed pointers.
 #[cfg(not(stage0), not(test))]
 #[lang="exchange_malloc"]
 #[inline]
-pub unsafe fn exchange_malloc(_align: u32, size: uintptr_t) -> *c_char {
+pub unsafe fn exchange_malloc(size: uintptr_t) -> *c_char {
     malloc_raw(size as uint) as *c_char
 }
 
diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs
index 309973def80..2d730b7a6a2 100644
--- a/src/libstd/vec.rs
+++ b/src/libstd/vec.rs
@@ -1771,7 +1771,7 @@ impl<'self,T> MutableVector<'self, T> for &'self mut [T] {
 
 }
 
-/// Trait for ~[T] where T is Cloneable
+/// Trait for &[T] where T is Cloneable
 pub trait MutableCloneableVector<T> {
     /// Copies as many elements from `src` as it can into `self`
     /// (the shorter of self.len() and src.len()). Returns the number of elements copied.