libstd: remove unnecessary as_slice()
calls
This commit is contained in:
parent
09f7713dd4
commit
60338d91c4
@ -677,8 +677,8 @@ mod tests {
|
||||
assert_eq!(test.to_ascii(), b);
|
||||
assert_eq!("( ;".to_ascii(), b);
|
||||
let v = vec![40u8, 32u8, 59u8];
|
||||
assert_eq!(v.as_slice().to_ascii(), b);
|
||||
assert_eq!("( ;".to_string().as_slice().to_ascii(), b);
|
||||
assert_eq!(v.to_ascii(), b);
|
||||
assert_eq!("( ;".to_string().to_ascii(), b);
|
||||
|
||||
assert_eq!("abCDef&?#".to_ascii().to_lowercase().into_string(), "abcdef&?#".to_string());
|
||||
assert_eq!("abCDef&?#".to_ascii().to_uppercase().into_string(), "ABCDEF&?#".to_string());
|
||||
@ -780,7 +780,7 @@ mod tests {
|
||||
while i <= 500 {
|
||||
let upper = if 'a' as u32 <= i && i <= 'z' as u32 { i + 'A' as u32 - 'a' as u32 }
|
||||
else { i };
|
||||
assert_eq!((from_u32(i).unwrap()).to_string().as_slice().to_ascii_upper(),
|
||||
assert_eq!((from_u32(i).unwrap()).to_string().to_ascii_upper(),
|
||||
(from_u32(upper).unwrap()).to_string())
|
||||
i += 1;
|
||||
}
|
||||
@ -796,7 +796,7 @@ mod tests {
|
||||
while i <= 500 {
|
||||
let lower = if 'A' as u32 <= i && i <= 'Z' as u32 { i + 'a' as u32 - 'A' as u32 }
|
||||
else { i };
|
||||
assert_eq!((from_u32(i).unwrap()).to_string().as_slice().to_ascii_lower(),
|
||||
assert_eq!((from_u32(i).unwrap()).to_string().to_ascii_lower(),
|
||||
(from_u32(lower).unwrap()).to_string())
|
||||
i += 1;
|
||||
}
|
||||
@ -850,7 +850,7 @@ mod tests {
|
||||
let c = i;
|
||||
let lower = if 'A' as u32 <= c && c <= 'Z' as u32 { c + 'a' as u32 - 'A' as u32 }
|
||||
else { c };
|
||||
assert!((from_u32(i).unwrap()).to_string().as_slice().eq_ignore_ascii_case(
|
||||
assert!((from_u32(i).unwrap()).to_string().eq_ignore_ascii_case(
|
||||
(from_u32(lower).unwrap()).to_string().as_slice()));
|
||||
i += 1;
|
||||
}
|
||||
|
@ -1546,7 +1546,7 @@ mod test_map {
|
||||
|
||||
DROP_VECTOR.with(|v| {
|
||||
for i in range(0u, 200) {
|
||||
assert_eq!(v.borrow().as_slice()[i], 0);
|
||||
assert_eq!(v.borrow()[i], 0);
|
||||
}
|
||||
});
|
||||
|
||||
@ -1558,7 +1558,7 @@ mod test_map {
|
||||
|
||||
DROP_VECTOR.with(|v| {
|
||||
for i in range(0u, 200) {
|
||||
assert_eq!(v.borrow().as_slice()[i], 1);
|
||||
assert_eq!(v.borrow()[i], 1);
|
||||
}
|
||||
});
|
||||
|
||||
@ -1569,27 +1569,27 @@ mod test_map {
|
||||
assert!(v.is_some());
|
||||
|
||||
DROP_VECTOR.with(|v| {
|
||||
assert_eq!(v.borrow().as_slice()[i], 1);
|
||||
assert_eq!(v.borrow().as_slice()[i+100], 1);
|
||||
assert_eq!(v.borrow()[i], 1);
|
||||
assert_eq!(v.borrow()[i+100], 1);
|
||||
});
|
||||
}
|
||||
|
||||
DROP_VECTOR.with(|v| {
|
||||
for i in range(0u, 50) {
|
||||
assert_eq!(v.borrow().as_slice()[i], 0);
|
||||
assert_eq!(v.borrow().as_slice()[i+100], 0);
|
||||
assert_eq!(v.borrow()[i], 0);
|
||||
assert_eq!(v.borrow()[i+100], 0);
|
||||
}
|
||||
|
||||
for i in range(50u, 100) {
|
||||
assert_eq!(v.borrow().as_slice()[i], 1);
|
||||
assert_eq!(v.borrow().as_slice()[i+100], 1);
|
||||
assert_eq!(v.borrow()[i], 1);
|
||||
assert_eq!(v.borrow()[i+100], 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
DROP_VECTOR.with(|v| {
|
||||
for i in range(0u, 200) {
|
||||
assert_eq!(v.borrow().as_slice()[i], 0);
|
||||
assert_eq!(v.borrow()[i], 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -1605,7 +1605,7 @@ mod test_map {
|
||||
|
||||
DROP_VECTOR.with(|v| {
|
||||
for i in range(0u, 200) {
|
||||
assert_eq!(v.borrow().as_slice()[i], 0);
|
||||
assert_eq!(v.borrow()[i], 0);
|
||||
}
|
||||
});
|
||||
|
||||
@ -1617,7 +1617,7 @@ mod test_map {
|
||||
|
||||
DROP_VECTOR.with(|v| {
|
||||
for i in range(0u, 200) {
|
||||
assert_eq!(v.borrow().as_slice()[i], 1);
|
||||
assert_eq!(v.borrow()[i], 1);
|
||||
}
|
||||
});
|
||||
|
||||
@ -1632,7 +1632,7 @@ mod test_map {
|
||||
|
||||
DROP_VECTOR.with(|v| {
|
||||
for i in range(0u, 200) {
|
||||
assert_eq!(v.borrow().as_slice()[i], 1);
|
||||
assert_eq!(v.borrow()[i], 1);
|
||||
}
|
||||
});
|
||||
|
||||
@ -1640,11 +1640,11 @@ mod test_map {
|
||||
|
||||
DROP_VECTOR.with(|v| {
|
||||
let nk = range(0u, 100).filter(|&i| {
|
||||
v.borrow().as_slice()[i] == 1
|
||||
v.borrow()[i] == 1
|
||||
}).count();
|
||||
|
||||
let nv = range(0u, 100).filter(|&i| {
|
||||
v.borrow().as_slice()[i+100] == 1
|
||||
v.borrow()[i+100] == 1
|
||||
}).count();
|
||||
|
||||
assert_eq!(nk, 50);
|
||||
@ -1654,7 +1654,7 @@ mod test_map {
|
||||
|
||||
DROP_VECTOR.with(|v| {
|
||||
for i in range(0u, 200) {
|
||||
assert_eq!(v.borrow().as_slice()[i], 0);
|
||||
assert_eq!(v.borrow()[i], 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -827,7 +827,7 @@ mod test_set {
|
||||
};
|
||||
|
||||
let v = hs.into_iter().collect::<Vec<char>>();
|
||||
assert!(['a', 'b'][] == v.as_slice() || ['b', 'a'][] == v.as_slice());
|
||||
assert!(['a', 'b'] == v || ['b', 'a'] == v);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -449,30 +449,30 @@ mod test {
|
||||
let nread = reader.read(&mut buf);
|
||||
assert_eq!(Ok(3), nread);
|
||||
let b: &[_] = &[5, 6, 7];
|
||||
assert_eq!(buf.as_slice(), b);
|
||||
assert_eq!(buf, b);
|
||||
|
||||
let mut buf = [0, 0];
|
||||
let nread = reader.read(&mut buf);
|
||||
assert_eq!(Ok(2), nread);
|
||||
let b: &[_] = &[0, 1];
|
||||
assert_eq!(buf.as_slice(), b);
|
||||
assert_eq!(buf, b);
|
||||
|
||||
let mut buf = [0];
|
||||
let nread = reader.read(&mut buf);
|
||||
assert_eq!(Ok(1), nread);
|
||||
let b: &[_] = &[2];
|
||||
assert_eq!(buf.as_slice(), b);
|
||||
assert_eq!(buf, b);
|
||||
|
||||
let mut buf = [0, 0, 0];
|
||||
let nread = reader.read(&mut buf);
|
||||
assert_eq!(Ok(1), nread);
|
||||
let b: &[_] = &[3, 0, 0];
|
||||
assert_eq!(buf.as_slice(), b);
|
||||
assert_eq!(buf, b);
|
||||
|
||||
let nread = reader.read(&mut buf);
|
||||
assert_eq!(Ok(1), nread);
|
||||
let b: &[_] = &[4, 0, 0];
|
||||
assert_eq!(buf.as_slice(), b);
|
||||
assert_eq!(buf, b);
|
||||
|
||||
assert!(reader.read(&mut buf).is_err());
|
||||
}
|
||||
|
@ -176,28 +176,28 @@ mod test {
|
||||
|
||||
assert_eq!(Ok(3), reader.read(&mut buf));
|
||||
let a: &[u8] = &[1,2,3];
|
||||
assert_eq!(a, buf.as_slice());
|
||||
assert_eq!(a, buf);
|
||||
|
||||
assert_eq!(Ok(3), reader.read(&mut buf));
|
||||
let a: &[u8] = &[4,5,6];
|
||||
assert_eq!(a, buf.as_slice());
|
||||
assert_eq!(a, buf);
|
||||
|
||||
assert_eq!(Ok(2), reader.read(&mut buf));
|
||||
let a: &[u8] = &[7,8,6];
|
||||
assert_eq!(a, buf.as_slice());
|
||||
assert_eq!(a, buf);
|
||||
|
||||
match reader.read(buf.as_mut_slice()) {
|
||||
Ok(..) => panic!(),
|
||||
Err(e) => assert_eq!(e.kind, io::EndOfFile),
|
||||
}
|
||||
assert_eq!(a, buf.as_slice());
|
||||
assert_eq!(a, buf);
|
||||
|
||||
// Ensure it continues to panic in the same way.
|
||||
match reader.read(buf.as_mut_slice()) {
|
||||
Ok(..) => panic!(),
|
||||
Err(e) => assert_eq!(e.kind, io::EndOfFile),
|
||||
}
|
||||
assert_eq!(a, buf.as_slice());
|
||||
assert_eq!(a, buf);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -837,7 +837,7 @@ mod test {
|
||||
macro_rules! error( ($e:expr, $s:expr) => (
|
||||
match $e {
|
||||
Ok(_) => panic!("Unexpected success. Should've been: {}", $s),
|
||||
Err(ref err) => assert!(err.to_string().as_slice().contains($s.as_slice()),
|
||||
Err(ref err) => assert!(err.to_string().contains($s.as_slice()),
|
||||
format!("`{}` did not contain `{}`", err, $s))
|
||||
}
|
||||
) )
|
||||
@ -995,7 +995,7 @@ mod test {
|
||||
}
|
||||
check!(unlink(filename));
|
||||
let read_str = str::from_utf8(&read_mem).unwrap();
|
||||
assert!(read_str.as_slice() == final_msg.as_slice());
|
||||
assert!(read_str == final_msg);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1103,7 +1103,7 @@ mod test {
|
||||
let f = dir.join(format!("{}.txt", n));
|
||||
let mut w = check!(File::create(&f));
|
||||
let msg_str = format!("{}{}", prefix, n.to_string());
|
||||
let msg = msg_str.as_slice().as_bytes();
|
||||
let msg = msg_str.as_bytes();
|
||||
check!(w.write(msg));
|
||||
}
|
||||
let files = check!(readdir(dir));
|
||||
|
@ -444,7 +444,7 @@ mod test {
|
||||
assert_eq!(writer.write(&[10]).unwrap_err().kind, io::EndOfFile);
|
||||
}
|
||||
let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8];
|
||||
assert_eq!(buf.as_slice(), b);
|
||||
assert_eq!(buf, b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -473,7 +473,7 @@ mod test {
|
||||
|
||||
}
|
||||
let b: &[_] = &[1, 3, 2, 0, 0, 0, 0, 4];
|
||||
assert_eq!(buf.as_slice(), b);
|
||||
assert_eq!(buf, b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -498,12 +498,12 @@ mod test {
|
||||
assert_eq!(reader.read(&mut buf), Ok(1));
|
||||
assert_eq!(reader.tell(), Ok(1));
|
||||
let b: &[_] = &[0];
|
||||
assert_eq!(buf.as_slice(), b);
|
||||
assert_eq!(buf, b);
|
||||
let mut buf = [0, ..4];
|
||||
assert_eq!(reader.read(&mut buf), Ok(4));
|
||||
assert_eq!(reader.tell(), Ok(5));
|
||||
let b: &[_] = &[1, 2, 3, 4];
|
||||
assert_eq!(buf.as_slice(), b);
|
||||
assert_eq!(buf, b);
|
||||
assert_eq!(reader.read(&mut buf), Ok(3));
|
||||
let b: &[_] = &[5, 6, 7];
|
||||
assert_eq!(buf[0..3], b);
|
||||
@ -551,12 +551,12 @@ mod test {
|
||||
assert_eq!(reader.read(&mut buf), Ok(1));
|
||||
assert_eq!(reader.tell(), Ok(1));
|
||||
let b: &[_] = &[0];
|
||||
assert_eq!(buf.as_slice(), b);
|
||||
assert_eq!(buf, b);
|
||||
let mut buf = [0, ..4];
|
||||
assert_eq!(reader.read(&mut buf), Ok(4));
|
||||
assert_eq!(reader.tell(), Ok(5));
|
||||
let b: &[_] = &[1, 2, 3, 4];
|
||||
assert_eq!(buf.as_slice(), b);
|
||||
assert_eq!(buf, b);
|
||||
assert_eq!(reader.read(&mut buf), Ok(3));
|
||||
let b: &[_] = &[5, 6, 7];
|
||||
assert_eq!(buf[0..3], b);
|
||||
@ -652,15 +652,15 @@ mod test {
|
||||
let mut buf = [0, ..3];
|
||||
assert!(r.read_at_least(buf.len(), &mut buf).is_ok());
|
||||
let b: &[_] = &[1, 2, 3];
|
||||
assert_eq!(buf.as_slice(), b);
|
||||
assert_eq!(buf, b);
|
||||
assert!(r.read_at_least(0, buf[mut ..0]).is_ok());
|
||||
assert_eq!(buf.as_slice(), b);
|
||||
assert_eq!(buf, b);
|
||||
assert!(r.read_at_least(buf.len(), &mut buf).is_ok());
|
||||
let b: &[_] = &[4, 5, 6];
|
||||
assert_eq!(buf.as_slice(), b);
|
||||
assert_eq!(buf, b);
|
||||
assert!(r.read_at_least(buf.len(), &mut buf).is_err());
|
||||
let b: &[_] = &[7, 8, 6];
|
||||
assert_eq!(buf.as_slice(), b);
|
||||
assert_eq!(buf, b);
|
||||
}
|
||||
|
||||
fn do_bench_mem_writer(b: &mut Bencher, times: uint, len: uint) {
|
||||
@ -757,7 +757,7 @@ mod test {
|
||||
for _i in range(0u, 10) {
|
||||
let mut buf = [0 as u8, .. 10];
|
||||
rdr.read(&mut buf).unwrap();
|
||||
assert_eq!(buf.as_slice(), [5, .. 10].as_slice());
|
||||
assert_eq!(buf, [5, .. 10]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -238,8 +238,8 @@ use os;
|
||||
use boxed::Box;
|
||||
use result::{Ok, Err, Result};
|
||||
use sys;
|
||||
use slice::{AsSlice, SlicePrelude};
|
||||
use str::{Str, StrPrelude};
|
||||
use slice::SlicePrelude;
|
||||
use str::StrPrelude;
|
||||
use str;
|
||||
use string::String;
|
||||
use uint;
|
||||
@ -316,7 +316,7 @@ impl IoError {
|
||||
pub fn from_errno(errno: uint, detail: bool) -> IoError {
|
||||
let mut err = sys::decode_error(errno as i32);
|
||||
if detail && err.kind == OtherIoError {
|
||||
err.detail = Some(os::error_string(errno).as_slice().chars()
|
||||
err.detail = Some(os::error_string(errno).chars()
|
||||
.map(|c| c.to_lowercase()).collect())
|
||||
}
|
||||
err
|
||||
|
@ -236,8 +236,8 @@ impl Command {
|
||||
// if the env is currently just inheriting from the parent's,
|
||||
// materialize the parent's env into a hashtable.
|
||||
self.env = Some(os::env_as_bytes().into_iter()
|
||||
.map(|(k, v)| (EnvKey(k.as_slice().to_c_str()),
|
||||
v.as_slice().to_c_str()))
|
||||
.map(|(k, v)| (EnvKey(k.to_c_str()),
|
||||
v.to_c_str()))
|
||||
.collect());
|
||||
self.env.as_mut().unwrap()
|
||||
}
|
||||
@ -973,7 +973,7 @@ mod tests {
|
||||
|
||||
let output = String::from_utf8(prog.wait_with_output().unwrap().output).unwrap();
|
||||
let parent_dir = os::getcwd().unwrap();
|
||||
let child_dir = Path::new(output.as_slice().trim());
|
||||
let child_dir = Path::new(output.trim());
|
||||
|
||||
let parent_stat = parent_dir.stat().unwrap();
|
||||
let child_stat = child_dir.stat().unwrap();
|
||||
@ -991,7 +991,7 @@ mod tests {
|
||||
let prog = pwd_cmd().cwd(&parent_dir).spawn().unwrap();
|
||||
|
||||
let output = String::from_utf8(prog.wait_with_output().unwrap().output).unwrap();
|
||||
let child_dir = Path::new(output.as_slice().trim());
|
||||
let child_dir = Path::new(output.trim());
|
||||
|
||||
let parent_stat = parent_dir.stat().unwrap();
|
||||
let child_stat = child_dir.stat().unwrap();
|
||||
@ -1031,8 +1031,7 @@ mod tests {
|
||||
for &(ref k, ref v) in r.iter() {
|
||||
// don't check windows magical empty-named variables
|
||||
assert!(k.is_empty() ||
|
||||
output.as_slice()
|
||||
.contains(format!("{}={}", *k, *v).as_slice()),
|
||||
output.contains(format!("{}={}", *k, *v).as_slice()),
|
||||
"output doesn't contain `{}={}`\n{}",
|
||||
k, v, output);
|
||||
}
|
||||
@ -1050,12 +1049,10 @@ mod tests {
|
||||
for &(ref k, ref v) in r.iter() {
|
||||
// don't check android RANDOM variables
|
||||
if *k != "RANDOM".to_string() {
|
||||
assert!(output.as_slice()
|
||||
.contains(format!("{}={}",
|
||||
assert!(output..contains(format!("{}={}",
|
||||
*k,
|
||||
*v).as_slice()) ||
|
||||
output.as_slice()
|
||||
.contains(format!("{}=\'{}\'",
|
||||
output..contains(format!("{}=\'{}\'",
|
||||
*k,
|
||||
*v).as_slice()));
|
||||
}
|
||||
@ -1084,7 +1081,7 @@ mod tests {
|
||||
let result = prog.wait_with_output().unwrap();
|
||||
let output = String::from_utf8_lossy(result.output.as_slice()).into_string();
|
||||
|
||||
assert!(output.as_slice().contains("RUN_TEST_NEW_ENV=123"),
|
||||
assert!(output.contains("RUN_TEST_NEW_ENV=123"),
|
||||
"didn't find RUN_TEST_NEW_ENV inside of:\n\n{}", output);
|
||||
}
|
||||
|
||||
@ -1094,7 +1091,7 @@ mod tests {
|
||||
let result = prog.wait_with_output().unwrap();
|
||||
let output = String::from_utf8_lossy(result.output.as_slice()).into_string();
|
||||
|
||||
assert!(output.as_slice().contains("RUN_TEST_NEW_ENV=123"),
|
||||
assert!(output.contains("RUN_TEST_NEW_ENV=123"),
|
||||
"didn't find RUN_TEST_NEW_ENV inside of:\n\n{}", output);
|
||||
}
|
||||
|
||||
|
@ -542,6 +542,6 @@ mod tests {
|
||||
panic!("my special message");
|
||||
});
|
||||
let s = r.read_to_string().unwrap();
|
||||
assert!(s.as_slice().contains("my special message"));
|
||||
assert!(s.contains("my special message"));
|
||||
}
|
||||
}
|
||||
|
@ -313,7 +313,7 @@ pub fn env_as_bytes() -> Vec<(Vec<u8>,Vec<u8>)> {
|
||||
fn env_convert(input: Vec<Vec<u8>>) -> Vec<(Vec<u8>, Vec<u8>)> {
|
||||
let mut pairs = Vec::new();
|
||||
for p in input.iter() {
|
||||
let mut it = p.as_slice().splitn(1, |b| *b == b'=');
|
||||
let mut it = p.splitn(1, |b| *b == b'=');
|
||||
let key = it.next().unwrap().to_vec();
|
||||
let default: &[u8] = &[];
|
||||
let val = it.next().unwrap_or(default).to_vec();
|
||||
@ -2066,7 +2066,7 @@ mod tests {
|
||||
#[cfg(unix)]
|
||||
fn join_paths_unix() {
|
||||
fn test_eq(input: &[&str], output: &str) -> bool {
|
||||
join_paths(input).unwrap().as_slice() == output.as_bytes()
|
||||
join_paths(input).unwrap() == output.as_bytes()
|
||||
}
|
||||
|
||||
assert!(test_eq(&[], ""));
|
||||
@ -2081,7 +2081,7 @@ mod tests {
|
||||
#[cfg(windows)]
|
||||
fn join_paths_windows() {
|
||||
fn test_eq(input: &[&str], output: &str) -> bool {
|
||||
join_paths(input).unwrap().as_slice() == output.as_bytes()
|
||||
join_paths(input).unwrap() == output.as_bytes()
|
||||
}
|
||||
|
||||
assert!(test_eq(&[], ""));
|
||||
|
@ -941,6 +941,6 @@ mod tests {
|
||||
|
||||
let input = r"\foo\bar\baz";
|
||||
let path: WindowsPath = WindowsPath::new(input.to_c_str());
|
||||
assert_eq!(path.as_str().unwrap(), input.as_slice());
|
||||
assert_eq!(path.as_str().unwrap(), input);
|
||||
}
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ impl GenericPathUnsafe for Path {
|
||||
unsafe fn set_filename_unchecked<T: BytesContainer>(&mut self, filename: T) {
|
||||
let filename = filename.container_as_bytes();
|
||||
match self.sepidx {
|
||||
None if b".." == self.repr.as_slice() => {
|
||||
None if b".." == self.repr => {
|
||||
let mut v = Vec::with_capacity(3 + filename.len());
|
||||
v.push_all(dot_dot_static);
|
||||
v.push(SEP_BYTE);
|
||||
@ -158,7 +158,7 @@ impl GenericPathUnsafe for Path {
|
||||
self.repr = Path::normalize(v.as_slice());
|
||||
}
|
||||
}
|
||||
self.sepidx = self.repr.as_slice().rposition_elem(&SEP_BYTE);
|
||||
self.sepidx = self.repr.rposition_elem(&SEP_BYTE);
|
||||
}
|
||||
|
||||
unsafe fn push_unchecked<T: BytesContainer>(&mut self, path: T) {
|
||||
@ -174,7 +174,7 @@ impl GenericPathUnsafe for Path {
|
||||
// FIXME: this is slow
|
||||
self.repr = Path::normalize(v.as_slice());
|
||||
}
|
||||
self.sepidx = self.repr.as_slice().rposition_elem(&SEP_BYTE);
|
||||
self.sepidx = self.repr.rposition_elem(&SEP_BYTE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -191,7 +191,7 @@ impl GenericPath for Path {
|
||||
|
||||
fn dirname<'a>(&'a self) -> &'a [u8] {
|
||||
match self.sepidx {
|
||||
None if b".." == self.repr.as_slice() => self.repr.as_slice(),
|
||||
None if b".." == self.repr => self.repr.as_slice(),
|
||||
None => dot_static,
|
||||
Some(0) => self.repr[..1],
|
||||
Some(idx) if self.repr[idx+1..] == b".." => self.repr.as_slice(),
|
||||
@ -201,8 +201,8 @@ impl GenericPath for Path {
|
||||
|
||||
fn filename<'a>(&'a self) -> Option<&'a [u8]> {
|
||||
match self.sepidx {
|
||||
None if b"." == self.repr.as_slice() ||
|
||||
b".." == self.repr.as_slice() => None,
|
||||
None if b"." == self.repr ||
|
||||
b".." == self.repr => None,
|
||||
None => Some(self.repr.as_slice()),
|
||||
Some(idx) if self.repr[idx+1..] == b".." => None,
|
||||
Some(0) if self.repr[1..].is_empty() => None,
|
||||
@ -212,20 +212,20 @@ impl GenericPath for Path {
|
||||
|
||||
fn pop(&mut self) -> bool {
|
||||
match self.sepidx {
|
||||
None if b"." == self.repr.as_slice() => false,
|
||||
None if b"." == self.repr => false,
|
||||
None => {
|
||||
self.repr = vec![b'.'];
|
||||
self.sepidx = None;
|
||||
true
|
||||
}
|
||||
Some(0) if b"/" == self.repr.as_slice() => false,
|
||||
Some(0) if b"/" == self.repr => false,
|
||||
Some(idx) => {
|
||||
if idx == 0 {
|
||||
self.repr.truncate(idx+1);
|
||||
} else {
|
||||
self.repr.truncate(idx);
|
||||
}
|
||||
self.sepidx = self.repr.as_slice().rposition_elem(&SEP_BYTE);
|
||||
self.sepidx = self.repr.rposition_elem(&SEP_BYTE);
|
||||
true
|
||||
}
|
||||
}
|
||||
@ -250,7 +250,7 @@ impl GenericPath for Path {
|
||||
} else {
|
||||
let mut ita = self.components();
|
||||
let mut itb = other.components();
|
||||
if b"." == self.repr.as_slice() {
|
||||
if b"." == self.repr {
|
||||
return match itb.next() {
|
||||
None => true,
|
||||
Some(b) => b != b".."
|
||||
@ -305,7 +305,7 @@ impl GenericPath for Path {
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(Path::new(comps.as_slice().connect_vec(&SEP_BYTE)))
|
||||
Some(Path::new(comps.connect_vec(&SEP_BYTE)))
|
||||
}
|
||||
}
|
||||
|
||||
@ -406,7 +406,7 @@ impl Path {
|
||||
|
||||
// None result means the byte vector didn't need normalizing
|
||||
fn normalize_helper<'a>(v: &'a [u8], is_abs: bool) -> Option<Vec<&'a [u8]>> {
|
||||
if is_abs && v.as_slice().is_empty() {
|
||||
if is_abs && v.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let mut comps: Vec<&'a [u8]> = vec![];
|
||||
@ -495,8 +495,8 @@ mod tests {
|
||||
t!(s: Path::new("foo/../../.."), "../..");
|
||||
t!(s: Path::new("foo/../../bar"), "../bar");
|
||||
|
||||
assert_eq!(Path::new(b"foo/bar").into_vec().as_slice(), b"foo/bar");
|
||||
assert_eq!(Path::new(b"/foo/../../bar").into_vec().as_slice(),
|
||||
assert_eq!(Path::new(b"foo/bar").into_vec(), b"foo/bar");
|
||||
assert_eq!(Path::new(b"/foo/../../bar").into_vec(),
|
||||
b"/bar");
|
||||
|
||||
let p = Path::new(b"foo/bar\x80");
|
||||
@ -536,7 +536,7 @@ mod tests {
|
||||
($path:expr, $disp:ident, $exp:expr) => (
|
||||
{
|
||||
let path = Path::new($path);
|
||||
assert!(path.$disp().to_string().as_slice() == $exp);
|
||||
assert!(path.$disp().to_string() == $exp);
|
||||
}
|
||||
)
|
||||
)
|
||||
@ -579,9 +579,9 @@ mod tests {
|
||||
{
|
||||
let path = Path::new($path);
|
||||
let f = format!("{}", path.display());
|
||||
assert!(f.as_slice() == $exp);
|
||||
assert!(f == $exp);
|
||||
let f = format!("{}", path.filename_display());
|
||||
assert!(f.as_slice() == $expf);
|
||||
assert!(f == $expf);
|
||||
}
|
||||
)
|
||||
)
|
||||
@ -1179,7 +1179,7 @@ mod tests {
|
||||
let path = Path::new($arg);
|
||||
let comps = path.components().collect::<Vec<&[u8]>>();
|
||||
let exp: &[&[u8]] = &[$($exp),*];
|
||||
assert_eq!(comps.as_slice(), exp);
|
||||
assert_eq!(comps, exp);
|
||||
let comps = path.components().rev().collect::<Vec<&[u8]>>();
|
||||
let exp = exp.iter().rev().map(|&x|x).collect::<Vec<&[u8]>>();
|
||||
assert_eq!(comps, exp)
|
||||
@ -1211,7 +1211,7 @@ mod tests {
|
||||
let path = Path::new($arg);
|
||||
let comps = path.str_components().collect::<Vec<Option<&str>>>();
|
||||
let exp: &[Option<&str>] = &$exp;
|
||||
assert_eq!(comps.as_slice(), exp);
|
||||
assert_eq!(comps, exp);
|
||||
let comps = path.str_components().rev().collect::<Vec<Option<&str>>>();
|
||||
let exp = exp.iter().rev().map(|&x|x).collect::<Vec<Option<&str>>>();
|
||||
assert_eq!(comps, exp);
|
||||
|
@ -181,7 +181,7 @@ impl GenericPathUnsafe for Path {
|
||||
unsafe fn set_filename_unchecked<T: BytesContainer>(&mut self, filename: T) {
|
||||
let filename = filename.container_as_str().unwrap();
|
||||
match self.sepidx_or_prefix_len() {
|
||||
None if ".." == self.repr.as_slice() => {
|
||||
None if ".." == self.repr => {
|
||||
let mut s = String::with_capacity(3 + filename.len());
|
||||
s.push_str("..");
|
||||
s.push(SEP);
|
||||
@ -191,22 +191,22 @@ impl GenericPathUnsafe for Path {
|
||||
None => {
|
||||
self.update_normalized(filename);
|
||||
}
|
||||
Some((_,idxa,end)) if self.repr.as_slice().slice(idxa,end) == ".." => {
|
||||
Some((_,idxa,end)) if self.repr.slice(idxa,end) == ".." => {
|
||||
let mut s = String::with_capacity(end + 1 + filename.len());
|
||||
s.push_str(self.repr.as_slice().slice_to(end));
|
||||
s.push_str(self.repr.slice_to(end));
|
||||
s.push(SEP);
|
||||
s.push_str(filename);
|
||||
self.update_normalized(s);
|
||||
}
|
||||
Some((idxb,idxa,_)) if self.prefix == Some(DiskPrefix) && idxa == self.prefix_len() => {
|
||||
let mut s = String::with_capacity(idxb + filename.len());
|
||||
s.push_str(self.repr.as_slice().slice_to(idxb));
|
||||
s.push_str(self.repr.slice_to(idxb));
|
||||
s.push_str(filename);
|
||||
self.update_normalized(s);
|
||||
}
|
||||
Some((idxb,_,_)) => {
|
||||
let mut s = String::with_capacity(idxb + 1 + filename.len());
|
||||
s.push_str(self.repr.as_slice().slice_to(idxb));
|
||||
s.push_str(self.repr.slice_to(idxb));
|
||||
s.push(SEP);
|
||||
s.push_str(filename);
|
||||
self.update_normalized(s);
|
||||
@ -355,21 +355,21 @@ impl GenericPath for Path {
|
||||
/// Always returns a `Some` value.
|
||||
fn dirname_str<'a>(&'a self) -> Option<&'a str> {
|
||||
Some(match self.sepidx_or_prefix_len() {
|
||||
None if ".." == self.repr.as_slice() => self.repr.as_slice(),
|
||||
None if ".." == self.repr => self.repr.as_slice(),
|
||||
None => ".",
|
||||
Some((_,idxa,end)) if self.repr.as_slice().slice(idxa, end) == ".." => {
|
||||
Some((_,idxa,end)) if self.repr.slice(idxa, end) == ".." => {
|
||||
self.repr.as_slice()
|
||||
}
|
||||
Some((idxb,_,end)) if self.repr.as_slice().slice(idxb, end) == "\\" => {
|
||||
Some((idxb,_,end)) if self.repr.slice(idxb, end) == "\\" => {
|
||||
self.repr.as_slice()
|
||||
}
|
||||
Some((0,idxa,_)) => self.repr.as_slice().slice_to(idxa),
|
||||
Some((0,idxa,_)) => self.repr.slice_to(idxa),
|
||||
Some((idxb,idxa,_)) => {
|
||||
match self.prefix {
|
||||
Some(DiskPrefix) | Some(VerbatimDiskPrefix) if idxb == self.prefix_len() => {
|
||||
self.repr.as_slice().slice_to(idxa)
|
||||
self.repr.slice_to(idxa)
|
||||
}
|
||||
_ => self.repr.as_slice().slice_to(idxb)
|
||||
_ => self.repr.slice_to(idxb)
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -414,14 +414,14 @@ impl GenericPath for Path {
|
||||
#[inline]
|
||||
fn pop(&mut self) -> bool {
|
||||
match self.sepidx_or_prefix_len() {
|
||||
None if "." == self.repr.as_slice() => false,
|
||||
None if "." == self.repr => false,
|
||||
None => {
|
||||
self.repr = String::from_str(".");
|
||||
self.sepidx = None;
|
||||
true
|
||||
}
|
||||
Some((idxb,idxa,end)) if idxb == idxa && idxb == end => false,
|
||||
Some((idxb,_,end)) if self.repr.as_slice().slice(idxb, end) == "\\" => false,
|
||||
Some((idxb,_,end)) if self.repr.slice(idxb, end) == "\\" => false,
|
||||
Some((idxb,idxa,_)) => {
|
||||
let trunc = match self.prefix {
|
||||
Some(DiskPrefix) | Some(VerbatimDiskPrefix) | None => {
|
||||
@ -441,15 +441,15 @@ impl GenericPath for Path {
|
||||
if self.prefix.is_some() {
|
||||
Some(Path::new(match self.prefix {
|
||||
Some(DiskPrefix) if self.is_absolute() => {
|
||||
self.repr.as_slice().slice_to(self.prefix_len()+1)
|
||||
self.repr.slice_to(self.prefix_len()+1)
|
||||
}
|
||||
Some(VerbatimDiskPrefix) => {
|
||||
self.repr.as_slice().slice_to(self.prefix_len()+1)
|
||||
self.repr.slice_to(self.prefix_len()+1)
|
||||
}
|
||||
_ => self.repr.as_slice().slice_to(self.prefix_len())
|
||||
_ => self.repr.slice_to(self.prefix_len())
|
||||
}))
|
||||
} else if is_vol_relative(self) {
|
||||
Some(Path::new(self.repr.as_slice().slice_to(1)))
|
||||
Some(Path::new(self.repr.slice_to(1)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@ -468,7 +468,7 @@ impl GenericPath for Path {
|
||||
fn is_absolute(&self) -> bool {
|
||||
match self.prefix {
|
||||
Some(DiskPrefix) => {
|
||||
let rest = self.repr.as_slice().slice_from(self.prefix_len());
|
||||
let rest = self.repr.slice_from(self.prefix_len());
|
||||
rest.len() > 0 && rest.as_bytes()[0] == SEP_BYTE
|
||||
}
|
||||
Some(_) => true,
|
||||
@ -490,7 +490,7 @@ impl GenericPath for Path {
|
||||
} else {
|
||||
let mut ita = self.str_components().map(|x|x.unwrap());
|
||||
let mut itb = other.str_components().map(|x|x.unwrap());
|
||||
if "." == self.repr.as_slice() {
|
||||
if "." == self.repr {
|
||||
return itb.next() != Some("..");
|
||||
}
|
||||
loop {
|
||||
@ -826,7 +826,7 @@ impl Path {
|
||||
|
||||
fn update_sepidx(&mut self) {
|
||||
let s = if self.has_nonsemantic_trailing_slash() {
|
||||
self.repr.as_slice().slice_to(self.repr.len()-1)
|
||||
self.repr.slice_to(self.repr.len()-1)
|
||||
} else { self.repr.as_slice() };
|
||||
let idx = s.rfind(if !prefix_is_verbatim(self.prefix) { is_sep }
|
||||
else { is_sep_verbatim });
|
||||
@ -922,7 +922,7 @@ pub fn make_non_verbatim(path: &Path) -> Option<Path> {
|
||||
}
|
||||
// now ensure normalization didn't change anything
|
||||
if repr.slice_from(path.prefix_len()) ==
|
||||
new_path.repr.as_slice().slice_from(new_path.prefix_len()) {
|
||||
new_path.repr.slice_from(new_path.prefix_len()) {
|
||||
Some(new_path)
|
||||
} else {
|
||||
None
|
||||
@ -1232,8 +1232,8 @@ mod tests {
|
||||
t!(s: Path::new("foo\\..\\..\\.."), "..\\..");
|
||||
t!(s: Path::new("foo\\..\\..\\bar"), "..\\bar");
|
||||
|
||||
assert_eq!(Path::new(b"foo\\bar").into_vec().as_slice(), b"foo\\bar");
|
||||
assert_eq!(Path::new(b"\\foo\\..\\..\\bar").into_vec().as_slice(), b"\\bar");
|
||||
assert_eq!(Path::new(b"foo\\bar").into_vec(), b"foo\\bar");
|
||||
assert_eq!(Path::new(b"\\foo\\..\\..\\bar").into_vec(), b"\\bar");
|
||||
|
||||
t!(s: Path::new("\\\\a"), "\\a");
|
||||
t!(s: Path::new("\\\\a\\"), "\\a");
|
||||
@ -1340,9 +1340,9 @@ mod tests {
|
||||
{
|
||||
let path = Path::new($path);
|
||||
let f = format!("{}", path.display());
|
||||
assert_eq!(f.as_slice(), $exp);
|
||||
assert_eq!(f, $exp);
|
||||
let f = format!("{}", path.filename_display());
|
||||
assert_eq!(f.as_slice(), $expf);
|
||||
assert_eq!(f, $expf);
|
||||
}
|
||||
)
|
||||
)
|
||||
@ -2245,7 +2245,7 @@ mod tests {
|
||||
let comps = path.str_components().map(|x|x.unwrap())
|
||||
.collect::<Vec<&str>>();
|
||||
let exp: &[&str] = &$exp;
|
||||
assert_eq!(comps.as_slice(), exp);
|
||||
assert_eq!(comps, exp);
|
||||
let comps = path.str_components().rev().map(|x|x.unwrap())
|
||||
.collect::<Vec<&str>>();
|
||||
let exp = exp.iter().rev().map(|&x|x).collect::<Vec<&str>>();
|
||||
@ -2302,7 +2302,7 @@ mod tests {
|
||||
let path = Path::new($path);
|
||||
let comps = path.components().collect::<Vec<&[u8]>>();
|
||||
let exp: &[&[u8]] = &$exp;
|
||||
assert_eq!(comps.as_slice(), exp);
|
||||
assert_eq!(comps, exp);
|
||||
let comps = path.components().rev().collect::<Vec<&[u8]>>();
|
||||
let exp = exp.iter().rev().map(|&x|x).collect::<Vec<&[u8]>>();
|
||||
assert_eq!(comps, exp);
|
||||
|
@ -529,7 +529,7 @@ mod test {
|
||||
let mut one = [1i];
|
||||
r.shuffle(&mut one);
|
||||
let b: &[_] = &[1];
|
||||
assert_eq!(one.as_slice(), b);
|
||||
assert_eq!(one, b);
|
||||
|
||||
let mut two = [1i, 2];
|
||||
r.shuffle(&mut two);
|
||||
@ -538,7 +538,7 @@ mod test {
|
||||
let mut x = [1i, 1, 1];
|
||||
r.shuffle(&mut x);
|
||||
let b: &[_] = &[1, 1, 1];
|
||||
assert_eq!(x.as_slice(), b);
|
||||
assert_eq!(x, b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -548,7 +548,7 @@ mod test {
|
||||
let mut v = [1i, 1, 1];
|
||||
r.shuffle(&mut v);
|
||||
let b: &[_] = &[1, 1, 1];
|
||||
assert_eq!(v.as_slice(), b);
|
||||
assert_eq!(v, b);
|
||||
assert_eq!(r.gen_range(0u, 1u), 0u);
|
||||
}
|
||||
|
||||
|
@ -376,8 +376,8 @@ pub fn readlink(p: &Path) -> IoResult<Path> {
|
||||
libc::VOLUME_NAME_DOS)
|
||||
});
|
||||
let ret = match ret {
|
||||
Some(ref s) if s.as_slice().starts_with(r"\\?\") => { // "
|
||||
Ok(Path::new(s.as_slice().slice_from(4)))
|
||||
Some(ref s) if s.starts_with(r"\\?\") => { // "
|
||||
Ok(Path::new(s.slice_from(4)))
|
||||
}
|
||||
Some(s) => Ok(Path::new(s)),
|
||||
None => Err(super::last_error()),
|
||||
|
@ -223,7 +223,7 @@ impl Process {
|
||||
|
||||
with_envp(cfg.env(), |envp| {
|
||||
with_dirp(cfg.cwd(), |dirp| {
|
||||
let mut cmd_str: Vec<u16> = cmd_str.as_slice().utf16_units().collect();
|
||||
let mut cmd_str: Vec<u16> = cmd_str.utf16_units().collect();
|
||||
cmd_str.push(0);
|
||||
let created = CreateProcessW(ptr::null(),
|
||||
cmd_str.as_mut_ptr(),
|
||||
@ -433,7 +433,7 @@ fn with_envp<K, V, T>(env: Option<&collections::HashMap<K, V>>,
|
||||
let kv = format!("{}={}",
|
||||
pair.ref0().container_as_str().unwrap(),
|
||||
pair.ref1().container_as_str().unwrap());
|
||||
blk.extend(kv.as_slice().utf16_units());
|
||||
blk.extend(kv.utf16_units());
|
||||
blk.push(0);
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,7 @@ impl TTY {
|
||||
pub fn write(&mut self, buf: &[u8]) -> IoResult<()> {
|
||||
let utf16 = match from_utf8(buf) {
|
||||
Some(utf8) => {
|
||||
utf8.as_slice().utf16_units().collect::<Vec<u16>>()
|
||||
utf8.utf16_units().collect::<Vec<u16>>()
|
||||
}
|
||||
None => return Err(invalid_encoding()),
|
||||
};
|
||||
|
@ -54,7 +54,7 @@ use result::Result;
|
||||
use rustrt::local::Local;
|
||||
use rustrt::task::Task;
|
||||
use rustrt::task;
|
||||
use str::{Str, SendStr};
|
||||
use str::SendStr;
|
||||
use string::{String, ToString};
|
||||
use sync::Future;
|
||||
|
||||
@ -242,7 +242,7 @@ pub fn name() -> Option<String> {
|
||||
|
||||
let task = Local::borrow(None::<Task>);
|
||||
match task.name {
|
||||
Some(ref name) => Some(name.as_slice().to_string()),
|
||||
Some(ref name) => Some(name.to_string()),
|
||||
None => None
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user