about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-01-07 17:56:32 -0800
committerbors <bors@rust-lang.org>2014-01-07 17:56:32 -0800
commita121f7bab3fe21f03cef6e214d5771bfe669e48c (patch)
treeaae19d70f56d01d89be7ed95a78b494e9f987e6d /src/libstd
parentaa1839bd693176f03f372fb34baa7b19b5030af7 (diff)
parent90b394514dad9df9c55b795be724093765d9df3a (diff)
downloadrust-a121f7bab3fe21f03cef6e214d5771bfe669e48c.tar.gz
rust-a121f7bab3fe21f03cef6e214d5771bfe669e48c.zip
auto merge of #10854 : Kimundi/rust/result_compose_map_mutate_or, r=alexcrichton
This implements parts of the changes to `Option` I proposed and discussed in this thread: https://mail.mozilla.org/pipermail/rust-dev/2013-November/006254.html, and on IRC.

In short, the string "default" should not be used in any context that has nothing to do with the `std::default::Default` trait.

This PR consists of this change:
- Renamed `map_default -> map_or` and `mutate_default -> mutate_or_set`.


Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/iter.rs4
-rw-r--r--src/libstd/option.rs8
-rw-r--r--src/libstd/path/windows.rs2
3 files changed, 7 insertions, 7 deletions
diff --git a/src/libstd/iter.rs b/src/libstd/iter.rs
index ee43435dab7..8d2ed62feb8 100644
--- a/src/libstd/iter.rs
+++ b/src/libstd/iter.rs
@@ -1600,8 +1600,8 @@ impl<'a, A, T: Iterator<A>, B, U: Iterator<B>> Iterator<B> for FlatMap<'a, A, T,
 
     #[inline]
     fn size_hint(&self) -> (uint, Option<uint>) {
-        let (flo, fhi) = self.frontiter.as_ref().map_default((0, Some(0)), |it| it.size_hint());
-        let (blo, bhi) = self.backiter.as_ref().map_default((0, Some(0)), |it| it.size_hint());
+        let (flo, fhi) = self.frontiter.as_ref().map_or((0, Some(0)), |it| it.size_hint());
+        let (blo, bhi) = self.backiter.as_ref().map_or((0, Some(0)), |it| it.size_hint());
         let lo = flo.saturating_add(blo);
         match (self.iter.size_hint(), fhi, bhi) {
             ((0, Some(0)), Some(a), Some(b)) => (lo, a.checked_add(&b)),
diff --git a/src/libstd/option.rs b/src/libstd/option.rs
index 35db800b3cc..a44b280aa84 100644
--- a/src/libstd/option.rs
+++ b/src/libstd/option.rs
@@ -164,7 +164,7 @@ impl<T> Option<T> {
 
     /// Applies a function to the contained value or returns a default.
     #[inline]
-    pub fn map_default<U>(self, def: U, f: |T| -> U) -> U {
+    pub fn map_or<U>(self, def: U, f: |T| -> U) -> U {
         match self { None => def, Some(t) => f(t) }
     }
 
@@ -179,7 +179,7 @@ impl<T> Option<T> {
 
     /// Apply a function to the contained value or set it to a default.
     /// Returns true if the contained value was mutated, or false if set to the default.
-    pub fn mutate_default(&mut self, def: T, f: |T| -> T) -> bool {
+    pub fn mutate_or_set(&mut self, def: T, f: |T| -> T) -> bool {
         if self.is_some() {
             *self = Some(f(self.take_unwrap()));
             true
@@ -695,12 +695,12 @@ mod tests {
         let mut x = Some(3i);
         assert!(x.mutate(|i| i+1));
         assert_eq!(x, Some(4i));
-        assert!(x.mutate_default(0, |i| i+1));
+        assert!(x.mutate_or_set(0, |i| i+1));
         assert_eq!(x, Some(5i));
         x = None;
         assert!(!x.mutate(|i| i+1));
         assert_eq!(x, None);
-        assert!(!x.mutate_default(0i, |i| i+1));
+        assert!(!x.mutate_or_set(0i, |i| i+1));
         assert_eq!(x, Some(0i));
     }
 
diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs
index 114f675cdba..913b314c00b 100644
--- a/src/libstd/path/windows.rs
+++ b/src/libstd/path/windows.rs
@@ -255,7 +255,7 @@ impl GenericPathUnsafe for Path {
             // if me is verbatim, we need to pre-normalize the new path
             let path_ = if is_verbatim(me) { Path::normalize__(path, None) }
                         else { None };
-            let pathlen = path_.as_ref().map_default(path.len(), |p| p.len());
+            let pathlen = path_.as_ref().map_or(path.len(), |p| p.len());
             let mut s = str::with_capacity(me.repr.len() + 1 + pathlen);
             s.push_str(me.repr);
             let plen = me.prefix_len();