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.
This commit is contained in:
Ben S 2015-07-15 21:40:20 +01:00
parent b6af699bbb
commit 21ee2fbb30
2 changed files with 6 additions and 12 deletions

View File

@ -148,17 +148,11 @@ impl<'dir> File<'dir> {
/// - `/` also has the empty string as its prefix. It does not have a
/// trailing slash, as the slash constitutes the 'name' of this file.
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();
// 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());
if component != &Component::RootDir {

View File

@ -1,5 +1,5 @@
#![feature(convert, fs_mode)]
#![feature(slice_extras, vec_resize)]
#![feature(slice_splits, vec_resize)]
extern crate ansi_term;
extern crate datetime;
@ -190,9 +190,9 @@ impl<'dir> Exa<'dir> {
#[cfg(not(test))]
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)) => {
let mut exa = Exa::new(options);
exa.load(&paths);