Skip to content

Commit fdf58e8

Browse files
committed
Upgrade to latest Rust (s/~str/StrBuf/)
See rust-lang/rust#14310
1 parent f65d170 commit fdf58e8

File tree

5 files changed

+28
-26
lines changed

5 files changed

+28
-26
lines changed

colours.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,20 @@ pub struct StyleStruct {
1616
}
1717

1818
impl Style {
19-
pub fn paint(&self, input: ~str) -> ~str {
19+
pub fn paint(&self, input: &str) -> StrBuf {
2020
match *self {
21-
Plain => input,
21+
Plain => input.to_strbuf(),
2222
Foreground(c) => c.paint(input),
2323
Style(s) => match s {
2424
StyleStruct { foreground, background, bold, underline } => {
25-
let bg: ~str = match background {
25+
let bg = match background {
2626
Some(c) => format!("{};", c as int + 10),
27-
None => "".to_owned(),
27+
None => "".to_strbuf()
2828
};
2929
let bo = if bold { "1;" } else { "" };
3030
let un = if underline { "4;" } else { "" };
31-
format!("\x1B[{}{}{}{}m{}\x1B[0m", bo, un, bg, foreground as int, input)
31+
let re = format!("\x1B[{}{}{}{}m{}\x1B[0m", bo, un, bg, foreground as int, input.to_strbuf());
32+
return re.to_owned();
3233
}
3334
}
3435
}
@@ -62,8 +63,9 @@ impl Style {
6263
}
6364

6465
impl Colour {
65-
pub fn paint(&self, input: &str) -> ~str {
66-
format!("\x1B[{}m{}\x1B[0m", *self as int, input)
66+
pub fn paint(&self, input: &str) -> StrBuf {
67+
let re = format!("\x1B[{}m{}\x1B[0m", *self as int, input);
68+
return re.to_owned();
6769
}
6870

6971
pub fn underline(&self) -> Style {
@@ -83,7 +85,7 @@ impl Colour {
8385
}
8486
}
8587

86-
pub fn strip_formatting(input: &~str) -> ~str {
88+
pub fn strip_formatting(input: &StrBuf) -> StrBuf {
8789
let re = regex!("\x1B\\[.+?m");
88-
re.replace_all(*input, "").to_owned()
90+
re.replace_all(input.as_slice(), "").to_owned()
8991
}

exa.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn list(opts: Options, path: Path) {
5858

5959
let columns = defaultColumns();
6060

61-
let table: Vec<Vec<~str>> = files.iter()
61+
let table: Vec<Vec<StrBuf>> = files.iter()
6262
.map(|p| File::from_path(p))
6363
.filter(|f| !f.is_dotfile() || opts.showInvisibles )
6464
.map(|f| columns.iter().map(|c| f.display(c)).collect())
@@ -76,7 +76,7 @@ fn list(opts: Options, path: Path) {
7676
} else {
7777
print!(" ");
7878
}
79-
print!("{}", cell);
79+
print!("{}", cell.as_slice());
8080
for _ in range(cell.len(), *length) {
8181
print!(" ");
8282
}

file.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ impl<'a> File<'a> {
3535
self.name.starts_with(".")
3636
}
3737

38-
pub fn display(&self, column: &Column) -> ~str {
38+
pub fn display(&self, column: &Column) -> StrBuf {
3939
match *column {
4040
Permissions => self.permissions(),
41-
FileName => self.file_colour().paint(self.name.to_owned()),
41+
FileName => self.file_colour().paint(self.name.as_slice()),
4242
FileSize(si) => self.file_size(si),
4343
User => get_user_name(self.stat.unstable.uid as i32).unwrap_or(self.stat.unstable.uid.to_str()),
4444
Group => get_group_name(self.stat.unstable.gid as u32).unwrap_or(self.stat.unstable.gid.to_str()),
4545
}
4646
}
4747

48-
fn file_size(&self, si: bool) -> ~str {
48+
fn file_size(&self, si: bool) -> StrBuf {
4949
let sizeStr = if si {
5050
formatBinaryBytes(self.stat.size)
5151
} else {
@@ -56,12 +56,12 @@ impl<'a> File<'a> {
5656
Green.normal()
5757
} else {
5858
Green.bold()
59-
}.paint(sizeStr);
59+
}.paint(sizeStr.as_slice());
6060
}
6161

62-
fn type_char(&self) -> ~str {
62+
fn type_char(&self) -> StrBuf {
6363
return match self.stat.kind {
64-
io::TypeFile => ".".to_owned(),
64+
io::TypeFile => ".".to_strbuf(),
6565
io::TypeDirectory => Blue.paint("d"),
6666
io::TypeNamedPipe => Yellow.paint("|"),
6767
io::TypeBlockSpecial => Purple.paint("s"),
@@ -83,7 +83,7 @@ impl<'a> File<'a> {
8383
}
8484
}
8585

86-
fn permissions(&self) -> ~str {
86+
fn permissions(&self) -> StrBuf {
8787
let bits = self.stat.perm;
8888
return format!("{}{}{}{}{}{}{}{}{}{}",
8989
self.type_char(),
@@ -100,10 +100,10 @@ impl<'a> File<'a> {
100100
}
101101
}
102102

103-
fn bit(bits: io::FilePermission, bit: io::FilePermission, other: &'static str, style: Style) -> ~str {
103+
fn bit(bits: io::FilePermission, bit: io::FilePermission, other: &'static str, style: Style) -> StrBuf {
104104
if bits.contains(bit) {
105-
style.paint(other.to_owned())
105+
style.paint(other.as_slice())
106106
} else {
107-
Black.bold().paint("-".to_owned())
107+
Black.bold().paint("-".as_slice())
108108
}
109109
}

format.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
fn formatBytes(mut amount: u64, kilo: u64, prefixes: ~[&str]) -> ~str {
1+
fn formatBytes(mut amount: u64, kilo: u64, prefixes: ~[&str]) -> StrBuf {
22
let mut prefix = 0;
33
while amount > kilo {
44
amount /= kilo;
@@ -7,10 +7,10 @@ fn formatBytes(mut amount: u64, kilo: u64, prefixes: ~[&str]) -> ~str {
77
return format!("{:4}{}", amount, prefixes[prefix]);
88
}
99

10-
pub fn formatBinaryBytes(amount: u64) -> ~str {
10+
pub fn formatBinaryBytes(amount: u64) -> StrBuf {
1111
formatBytes(amount, 1024, ~[ "B ", "KiB", "MiB", "GiB", "TiB" ])
1212
}
1313

14-
pub fn formatDecimalBytes(amount: u64) -> ~str {
14+
pub fn formatDecimalBytes(amount: u64) -> StrBuf {
1515
formatBytes(amount, 1000, ~[ "B ", "KB", "MB", "GB", "TB" ])
1616
}

unix.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ mod c {
3434
}
3535
}
3636

37-
pub fn get_user_name(uid: i32) -> Option<~str> {
37+
pub fn get_user_name(uid: i32) -> Option<StrBuf> {
3838
let pw = unsafe { c::getpwuid(uid) };
3939
if pw.is_not_null() {
4040
return unsafe { Some(from_c_str(read(pw).pw_name)) };
@@ -44,7 +44,7 @@ pub fn get_user_name(uid: i32) -> Option<~str> {
4444
}
4545
}
4646

47-
pub fn get_group_name(gid: u32) -> Option<~str> {
47+
pub fn get_group_name(gid: u32) -> Option<StrBuf> {
4848
let gr = unsafe { c::getgrgid(gid) };
4949
if gr.is_not_null() {
5050
return unsafe { Some(from_c_str(read(gr).gr_name)) };

0 commit comments

Comments
 (0)