Explorar o código

Use new slice_splits functions

These replace `init()` and `tail()` which are deprecated in favour of these.

In fact, it's a good thing they're deprecated, because part of the path_prefix code involved working around a call to init() that would panic otherwise - doing the same check with an `Option` is much more ergonomic.
Ben S %!s(int64=10) %!d(string=hai) anos
pai
achega
21ee2fbb30
Modificáronse 2 ficheiros con 6 adicións e 12 borrados
  1. 3 9
      src/file.rs
  2. 3 3
      src/main.rs

+ 3 - 9
src/file.rs

@@ -148,17 +148,11 @@ impl<'dir> File<'dir> {
     /// - `/` also has the empty string as its prefix. It does not have a
     /// - `/` also has the empty string as its prefix. It does not have a
     ///   trailing slash, as the slash constitutes the 'name' of this file.
     ///   trailing slash, as the slash constitutes the 'name' of this file.
     pub fn path_prefix(&self) -> String {
     pub fn path_prefix(&self) -> String {
-        let path_bytes: Vec<Component> = self.path.components().collect();
+        let components: Vec<Component> = self.path.components().collect();
         let mut path_prefix = String::new();
         let mut path_prefix = String::new();
 
 
-        // TODO: I'm not sure if it's even possible for a file to have
-        // an empty set of components...
-        if !path_bytes.is_empty() {
-
-            // Use init() to add all but the last component of the
-            // path to the prefix. init() panics when given an
-            // empty list, hence the check.
-            for component in path_bytes.init().iter() {
+        if let Some((_, components_init)) = components.split_last() {
+            for component in components_init.iter() {
                 path_prefix.push_str(&*component.as_os_str().to_string_lossy());
                 path_prefix.push_str(&*component.as_os_str().to_string_lossy());
 
 
                 if component != &Component::RootDir {
                 if component != &Component::RootDir {

+ 3 - 3
src/main.rs

@@ -1,5 +1,5 @@
 #![feature(convert, fs_mode)]
 #![feature(convert, fs_mode)]
-#![feature(slice_extras, vec_resize)]
+#![feature(slice_splits, vec_resize)]
 
 
 extern crate ansi_term;
 extern crate ansi_term;
 extern crate datetime;
 extern crate datetime;
@@ -190,9 +190,9 @@ impl<'dir> Exa<'dir> {
 
 
 #[cfg(not(test))]
 #[cfg(not(test))]
 fn main() {
 fn main() {
-    let args: Vec<String> = env::args().collect();
+    let args: Vec<String> = env::args().skip(1).collect();
 
 
-    match Options::getopts(args.tail()) {
+    match Options::getopts(&args) {
         Ok((options, paths)) => {
         Ok((options, paths)) => {
             let mut exa = Exa::new(options);
             let mut exa = Exa::new(options);
             exa.load(&paths);
             exa.load(&paths);