From 90b394514dad9df9c55b795be724093765d9df3a Mon Sep 17 00:00:00 2001 From: Marvin Löbel Date: Fri, 6 Dec 2013 19:51:10 +0100 Subject: Renamed Option::map_default and mutate_default to map_or and mutate_or_set --- src/libstd/iter.rs | 4 ++-- src/libstd/option.rs | 8 ++++---- src/libstd/path/windows.rs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/libstd') 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, B, U: Iterator> Iterator for FlatMap<'a, A, T, #[inline] fn size_hint(&self) -> (uint, Option) { - 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 Option { /// Applies a function to the contained value or returns a default. #[inline] - pub fn map_default(self, def: U, f: |T| -> U) -> U { + pub fn map_or(self, def: U, f: |T| -> U) -> U { match self { None => def, Some(t) => f(t) } } @@ -179,7 +179,7 @@ impl Option { /// 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(); -- cgit 1.4.1-3-g733a5