]> git.lizzy.rs Git - rust.git/commitdiff
Use four-space indentation, add trailing commas, and remove unnecessary uses of the...
authorBrendan Zabarauskas <bjzaba@yahoo.com.au>
Sat, 18 May 2013 06:52:11 +0000 (16:52 +1000)
committerBrendan Zabarauskas <bjzaba@yahoo.com.au>
Sat, 18 May 2013 07:29:19 +0000 (17:29 +1000)
src/libcore/either.rs
src/libcore/option.rs
src/libcore/path.rs

index ab52822849cfb55377dc199e05d1ef6cb894be32..f89bb3b2f90646c993d6e40ce9fb690d7c873a4a 100644 (file)
@@ -35,8 +35,8 @@ pub enum Either<T, U> {
 pub fn either<T, U, V>(f_left: &fn(&T) -> V,
                        f_right: &fn(&U) -> V, value: &Either<T, U>) -> V {
     match *value {
-      Left(ref l) => f_left(l),
-      Right(ref r) => f_right(r)
+        Left(ref l) => f_left(l),
+        Right(ref r) => f_right(r)
     }
 }
 
@@ -73,8 +73,8 @@ pub fn partition<T, U>(eithers: ~[Either<T, U>]) -> (~[T], ~[U]) {
     let mut rights: ~[U] = ~[];
     do vec::consume(eithers) |_i, elt| {
         match elt {
-          Left(l) => lefts.push(l),
-          Right(r) => rights.push(r)
+            Left(l) => lefts.push(l),
+            Right(r) => rights.push(r)
         }
     }
     return (lefts, rights);
@@ -84,8 +84,8 @@ pub fn partition<T, U>(eithers: ~[Either<T, U>]) -> (~[T], ~[U]) {
 #[inline(always)]
 pub fn flip<T, U>(eith: Either<T, U>) -> Either<U, T> {
     match eith {
-      Right(r) => Left(r),
-      Left(l) => Right(l)
+        Right(r) => Left(r),
+        Left(l) => Right(l)
     }
 }
 
@@ -96,21 +96,27 @@ pub fn flip<T, U>(eith: Either<T, U>) -> Either<U, T> {
 #[inline(always)]
 pub fn to_result<T, U>(eith: Either<T, U>) -> Result<U, T> {
     match eith {
-      Right(r) => result::Ok(r),
-      Left(l) => result::Err(l)
+        Right(r) => result::Ok(r),
+        Left(l) => result::Err(l)
     }
 }
 
 /// Checks whether the given value is a left
 #[inline(always)]
 pub fn is_left<T, U>(eith: &Either<T, U>) -> bool {
-    match *eith { Left(_) => true, _ => false }
+    match *eith {
+        Left(_) => true,
+        _ => false
+    }
 }
 
 /// Checks whether the given value is a right
 #[inline(always)]
 pub fn is_right<T, U>(eith: &Either<T, U>) -> bool {
-    match *eith { Right(_) => true, _ => false }
+    match *eith {
+        Right(_) => true,
+        _ => false
+    }
 }
 
 /// Retrieves the value in the left branch. Fails if the either is Right.
index e1bd72f67f16f68707ab8d742bdbce7cafd67b72..0212d4abd29d6955b0a67e9c0bcf64ff2684d24f 100644 (file)
@@ -89,11 +89,11 @@ fn le(&self, other: &Option<T>) -> bool {
     }
 
     fn ge(&self, other: &Option<T>) -> bool {
-        ! (self < other)
+        !(self < other)
     }
 
     fn gt(&self, other: &Option<T>) -> bool {
-        ! (self <= other)
+        !(self <= other)
     }
 }
 
index c359b657cd3d714f2b92a910efa2d2beb7861a8c..8a5d9c0416d07d4f4ff060885f284425ecccbe7f 100644 (file)
@@ -452,8 +452,10 @@ fn from_str(s: &str) -> PosixPath {
             components.push(s.to_owned())
         }
         let is_absolute = (s.len() != 0 && s[0] == '/' as u8);
-        return PosixPath { is_absolute: is_absolute,
-                           components: components }
+        PosixPath {
+            is_absolute: is_absolute,
+            components: components,
+        }
     }
 
     fn dirname(&self) -> ~str {
@@ -466,40 +468,40 @@ fn dirname(&self) -> ~str {
 
     fn filename(&self) -> Option<~str> {
         match self.components.len() {
-          0 => None,
-          n => Some(copy self.components[n - 1])
+            0 => None,
+            n => Some(copy self.components[n - 1]),
         }
     }
 
     fn filestem(&self) -> Option<~str> {
         match self.filename() {
-          None => None,
-          Some(ref f) => {
-            match str::rfind_char(*f, '.') {
-              Some(p) => Some(f.slice(0, p).to_owned()),
-              None => Some(copy *f)
+            None => None,
+            Some(ref f) => {
+                match str::rfind_char(*f, '.') {
+                    Some(p) => Some(f.slice(0, p).to_owned()),
+                    None => Some(copy *f),
+                }
             }
-          }
         }
     }
 
     fn filetype(&self) -> Option<~str> {
         match self.filename() {
-          None => None,
-          Some(ref f) => {
-            match str::rfind_char(*f, '.') {
-              Some(p) if p < f.len() => Some(f.slice(p, f.len()).to_owned()),
-              _ => None
+            None => None,
+            Some(ref f) => {
+                match str::rfind_char(*f, '.') {
+                    Some(p) if p < f.len() => Some(f.slice(p, f.len()).to_owned()),
+                    _ => None,
+                }
             }
-          }
         }
     }
 
     fn with_dirname(&self, d: &str) -> PosixPath {
         let dpath = PosixPath(d);
         match self.filename() {
-          Some(ref f) => dpath.push(*f),
-          None => dpath
+            Some(ref f) => dpath.push(*f),
+            None => dpath,
         }
     }
 
@@ -510,8 +512,8 @@ fn with_filename(&self, f: &str) -> PosixPath {
 
     fn with_filestem(&self, s: &str) -> PosixPath {
         match self.filetype() {
-          None => self.with_filename(s),
-          Some(ref t) => self.with_filename(str::to_owned(s) + *t)
+            None => self.with_filename(s),
+            Some(ref t) => self.with_filename(str::to_owned(s) + *t),
         }
     }
 
@@ -536,8 +538,10 @@ fn file_path(&self) -> PosixPath {
           None => ~[],
           Some(ref f) => ~[copy *f]
         };
-        return PosixPath { is_absolute: false,
-                           components: cs }
+        PosixPath {
+            is_absolute: false,
+            components: cs,
+        }
     }
 
     fn push_rel(&self, other: &PosixPath) -> PosixPath {
@@ -547,8 +551,10 @@ fn push_rel(&self, other: &PosixPath) -> PosixPath {
 
     fn unsafe_join(&self, other: &PosixPath) -> PosixPath {
         if other.is_absolute {
-            PosixPath { is_absolute: true,
-                        components: copy other.components }
+            PosixPath {
+                is_absolute: true,
+                components: copy other.components,
+            }
         } else {
             self.push_rel(other)
         }
@@ -567,8 +573,10 @@ fn push_many(&self, cs: &[~str]) -> PosixPath {
             }
             v.push_all_move(ss);
         }
-        PosixPath { is_absolute: self.is_absolute,
-                    components: v }
+        PosixPath {
+            is_absolute: self.is_absolute,
+            components: v,
+        }
     }
 
     fn push(&self, s: &str) -> PosixPath {
@@ -586,19 +594,17 @@ fn pop(&self) -> PosixPath {
         if cs.len() != 0 {
             cs.pop();
         }
-        return PosixPath {
+        PosixPath {
             is_absolute: self.is_absolute,
-            components: cs
-        }
-                          //..self }
+            components: cs,
+        } //..self }
     }
 
     fn normalize(&self) -> PosixPath {
-        return PosixPath {
+        PosixPath {
             is_absolute: self.is_absolute,
-            components: normalize(self.components)
-          //  ..self
-        }
+            components: normalize(self.components),
+        } // ..self }
     }
 
     fn is_absolute(&self) -> bool {
@@ -658,10 +664,12 @@ fn from_str(s: &str) -> WindowsPath {
             components.push(s.to_owned())
         }
         let is_absolute = (rest.len() != 0 && windows::is_sep(rest[0]));
-        return WindowsPath { host: host,
-                             device: device,
-                             is_absolute: is_absolute,
-                             components: components }
+        WindowsPath {
+            host: host,
+            device: device,
+            is_absolute: is_absolute,
+            components: components,
+        }
     }
 
     fn dirname(&self) -> ~str {
@@ -674,20 +682,20 @@ fn dirname(&self) -> ~str {
 
     fn filename(&self) -> Option<~str> {
         match self.components.len() {
-          0 => None,
-          n => Some(copy self.components[n - 1])
+            0 => None,
+            n => Some(copy self.components[n - 1]),
         }
     }
 
     fn filestem(&self) -> Option<~str> {
         match self.filename() {
-          None => None,
-          Some(ref f) => {
-            match str::rfind_char(*f, '.') {
-              Some(p) => Some(f.slice(0, p).to_owned()),
-              None => Some(copy *f)
+            None => None,
+            Some(ref f) => {
+                match str::rfind_char(*f, '.') {
+                    Some(p) => Some(f.slice(0, p).to_owned()),
+                    None => Some(copy *f),
+                }
             }
-          }
         }
     }
 
@@ -696,8 +704,8 @@ fn filetype(&self) -> Option<~str> {
           None => None,
           Some(ref f) => {
             match str::rfind_char(*f, '.') {
-              Some(p) if p < f.len() => Some(f.slice(p, f.len()).to_owned()),
-              _ => None
+                Some(p) if p < f.len() => Some(f.slice(p, f.len()).to_owned()),
+                _ => None,
             }
           }
         }
@@ -706,8 +714,8 @@ fn filetype(&self) -> Option<~str> {
     fn with_dirname(&self, d: &str) -> WindowsPath {
         let dpath = WindowsPath(d);
         match self.filename() {
-          Some(ref f) => dpath.push(*f),
-          None => dpath
+            Some(ref f) => dpath.push(*f),
+            None => dpath,
         }
     }
 
@@ -718,8 +726,8 @@ fn with_filename(&self, f: &str) -> WindowsPath {
 
     fn with_filestem(&self, s: &str) -> WindowsPath {
         match self.filetype() {
-          None => self.with_filename(s),
-          Some(ref t) => self.with_filename(str::to_owned(s) + *t)
+            None => self.with_filename(s),
+            Some(ref t) => self.with_filename(str::to_owned(s) + *t),
         }
     }
 
@@ -740,14 +748,15 @@ fn dir_path(&self) -> WindowsPath {
     }
 
     fn file_path(&self) -> WindowsPath {
-        let cs = match self.filename() {
-          None => ~[],
-          Some(ref f) => ~[copy *f]
-        };
-        return WindowsPath { host: None,
-                             device: None,
-                             is_absolute: false,
-                             components: cs }
+        WindowsPath {
+            host: None,
+            device: None,
+            is_absolute: false,
+            components: match self.filename() {
+                None => ~[],
+                Some(ref f) => ~[copy *f],
+            }
+        }
     }
 
     fn push_rel(&self, other: &WindowsPath) -> WindowsPath {
@@ -768,7 +777,7 @@ fn unsafe_join(&self, other: &WindowsPath) -> WindowsPath {
                     host: Some(host),
                     device: copy other.device,
                     is_absolute: true,
-                    components: copy other.components
+                    components: copy other.components,
                 };
             }
             _ => {}
@@ -781,7 +790,7 @@ fn unsafe_join(&self, other: &WindowsPath) -> WindowsPath {
                     host: None,
                     device: Some(device),
                     is_absolute: true,
-                    components: copy other.components
+                    components: copy other.components,
                 };
             }
             _ => {}
@@ -793,7 +802,7 @@ fn unsafe_join(&self, other: &WindowsPath) -> WindowsPath {
             host: copy self.host,
             device: copy self.device,
             is_absolute: self.is_absolute || other.is_absolute,
-            components: copy other.components
+            components: copy other.components,
         }
     }
 
@@ -822,7 +831,7 @@ fn push_many(&self, cs: &[~str]) -> WindowsPath {
             v.push_all_move(ss);
         }
         // tedious, but as-is, we can't use ..self
-        return WindowsPath {
+        WindowsPath {
             host: copy self.host,
             device: copy self.device,
             is_absolute: self.is_absolute,
@@ -837,7 +846,7 @@ fn push(&self, s: &str) -> WindowsPath {
             ss.push(s.to_owned())
         }
         v.push_all_move(ss);
-        return WindowsPath { components: v, ..copy *self }
+        WindowsPath { components: v, ..copy *self }
     }
 
     fn pop(&self) -> WindowsPath {
@@ -845,16 +854,16 @@ fn pop(&self) -> WindowsPath {
         if cs.len() != 0 {
             cs.pop();
         }
-        return WindowsPath {
+        WindowsPath {
             host: copy self.host,
             device: copy self.device,
             is_absolute: self.is_absolute,
-            components: cs
+            components: cs,
         }
     }
 
     fn normalize(&self) -> WindowsPath {
-        return WindowsPath {
+        WindowsPath {
             host: copy self.host,
             device: match self.device {
                 None => None,