From d6e34723b974f44accac66748473aa7e8961ec9f Mon Sep 17 00:00:00 2001 From: Ben S Date: Mon, 5 May 2014 10:51:24 +0100 Subject: [PATCH] Upgrade to latest Rust nightly Replace ~strs with either &'static strs or .to_owned() strs where appropriate Fields now seem to be private by default - good! --- colours.rs | 6 +++--- exa.rs | 9 +++++++-- file.rs | 32 ++++++++++++++++++-------------- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/colours.rs b/colours.rs index cfb2594..06182a0 100644 --- a/colours.rs +++ b/colours.rs @@ -24,10 +24,10 @@ impl Style { StyleStruct { foreground, background, bold, underline } => { let bg: ~str = match background { Some(c) => format!("{};", c as int + 10), - None => ~"", + None => "".to_owned(), }; - let bo: ~str = if bold { ~"1;" } else { ~"" }; - let un: ~str = if underline { ~"4;" } else { ~"" }; + let bo = if bold { "1;" } else { "" }; + let un = if underline { "4;" } else { "" }; format!("\x1B[{}{}{}{}m{}\x1B[0m", bo, un, bg, foreground as int, input) } } diff --git a/exa.rs b/exa.rs index a94d056..c8b16f9 100644 --- a/exa.rs +++ b/exa.rs @@ -30,7 +30,12 @@ fn main() { showInvisibles: matches.opt_present("all") }; - let strs = if matches.free.is_empty() {vec!(~"./")} else {matches.free.clone()}; + let strs = if matches.free.is_empty() { + vec!("./".to_owned()) + } + else { + matches.free.clone() + }; for dir in strs.move_iter() { list(opts, Path::new(dir)) @@ -46,7 +51,7 @@ fn list(opts: Options, path: Path) { for subpath in files.iter() { let file = File::from_path(subpath); - if file.name.starts_with(".") && !opts.showInvisibles { + if file.is_dotfile() && !opts.showInvisibles { continue; } diff --git a/file.rs b/file.rs index 92b2e0d..24ef0e6 100644 --- a/file.rs +++ b/file.rs @@ -30,6 +30,10 @@ impl<'a> File<'a> { return File { path: path, stat: stat, name: filename }; } + pub fn is_dotfile(&self) -> bool { + self.name.starts_with(".") + } + pub fn display(&self, column: &Column) -> ~str { match *column { Permissions => self.permissions(), @@ -54,12 +58,12 @@ impl<'a> File<'a> { fn type_char(&self) -> ~str { return match self.stat.kind { - io::TypeFile => ~".", + io::TypeFile => ".".to_owned(), io::TypeDirectory => Blue.paint("d"), io::TypeNamedPipe => Yellow.paint("|"), io::TypeBlockSpecial => Purple.paint("s"), io::TypeSymlink => Cyan.paint("l"), - _ => ~"?", + _ => "?".to_owned(), } } @@ -80,23 +84,23 @@ impl<'a> File<'a> { let bits = self.stat.perm; return format!("{}{}{}{}{}{}{}{}{}{}", self.type_char(), - bit(bits, io::UserRead, ~"r", Yellow.bold()), - bit(bits, io::UserWrite, ~"w", Red.bold()), - bit(bits, io::UserExecute, ~"x", Green.bold().underline()), - bit(bits, io::GroupRead, ~"r", Yellow.normal()), - bit(bits, io::GroupWrite, ~"w", Red.normal()), - bit(bits, io::GroupExecute, ~"x", Green.normal()), - bit(bits, io::OtherRead, ~"r", Yellow.normal()), - bit(bits, io::OtherWrite, ~"w", Red.normal()), - bit(bits, io::OtherExecute, ~"x", Green.normal()), + bit(bits, io::UserRead, "r", Yellow.bold()), + bit(bits, io::UserWrite, "w", Red.bold()), + bit(bits, io::UserExecute, "x", Green.bold().underline()), + bit(bits, io::GroupRead, "r", Yellow.normal()), + bit(bits, io::GroupWrite, "w", Red.normal()), + bit(bits, io::GroupExecute, "x", Green.normal()), + bit(bits, io::OtherRead, "r", Yellow.normal()), + bit(bits, io::OtherWrite, "w", Red.normal()), + bit(bits, io::OtherExecute, "x", Green.normal()), ); } } -fn bit(bits: u32, bit: u32, other: ~str, style: Style) -> ~str { +fn bit(bits: u32, bit: u32, other: &'static str, style: Style) -> ~str { if bits & bit == bit { - style.paint(other) + style.paint(other.to_owned()) } else { - Black.bold().paint(~"-") + Black.bold().paint("-".to_owned()) } } -- GitLab