libstd: remove unnecessary as_slice() calls

This commit is contained in:
Jorge Aparicio 2014-11-27 14:43:55 -05:00
parent 09f7713dd4
commit 60338d91c4
19 changed files with 118 additions and 121 deletions

View File

@ -677,8 +677,8 @@ mod tests {
assert_eq!(test.to_ascii(), b); assert_eq!(test.to_ascii(), b);
assert_eq!("( ;".to_ascii(), b); assert_eq!("( ;".to_ascii(), b);
let v = vec![40u8, 32u8, 59u8]; let v = vec![40u8, 32u8, 59u8];
assert_eq!(v.as_slice().to_ascii(), b); assert_eq!(v.to_ascii(), b);
assert_eq!("( ;".to_string().as_slice().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_lowercase().into_string(), "abcdef&?#".to_string());
assert_eq!("abCDef&?#".to_ascii().to_uppercase().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 { while i <= 500 {
let upper = if 'a' as u32 <= i && i <= 'z' as u32 { i + 'A' as u32 - 'a' as u32 } let upper = if 'a' as u32 <= i && i <= 'z' as u32 { i + 'A' as u32 - 'a' as u32 }
else { i }; 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()) (from_u32(upper).unwrap()).to_string())
i += 1; i += 1;
} }
@ -796,7 +796,7 @@ mod tests {
while i <= 500 { while i <= 500 {
let lower = if 'A' as u32 <= i && i <= 'Z' as u32 { i + 'a' as u32 - 'A' as u32 } let lower = if 'A' as u32 <= i && i <= 'Z' as u32 { i + 'a' as u32 - 'A' as u32 }
else { i }; 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()) (from_u32(lower).unwrap()).to_string())
i += 1; i += 1;
} }
@ -850,7 +850,7 @@ mod tests {
let c = i; let c = i;
let lower = if 'A' as u32 <= c && c <= 'Z' as u32 { c + 'a' as u32 - 'A' as u32 } let lower = if 'A' as u32 <= c && c <= 'Z' as u32 { c + 'a' as u32 - 'A' as u32 }
else { c }; 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())); (from_u32(lower).unwrap()).to_string().as_slice()));
i += 1; i += 1;
} }

View File

@ -1546,7 +1546,7 @@ mod test_map {
DROP_VECTOR.with(|v| { DROP_VECTOR.with(|v| {
for i in range(0u, 200) { 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| { DROP_VECTOR.with(|v| {
for i in range(0u, 200) { 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()); assert!(v.is_some());
DROP_VECTOR.with(|v| { DROP_VECTOR.with(|v| {
assert_eq!(v.borrow().as_slice()[i], 1); assert_eq!(v.borrow()[i], 1);
assert_eq!(v.borrow().as_slice()[i+100], 1); assert_eq!(v.borrow()[i+100], 1);
}); });
} }
DROP_VECTOR.with(|v| { DROP_VECTOR.with(|v| {
for i in range(0u, 50) { for i in range(0u, 50) {
assert_eq!(v.borrow().as_slice()[i], 0); assert_eq!(v.borrow()[i], 0);
assert_eq!(v.borrow().as_slice()[i+100], 0); assert_eq!(v.borrow()[i+100], 0);
} }
for i in range(50u, 100) { for i in range(50u, 100) {
assert_eq!(v.borrow().as_slice()[i], 1); assert_eq!(v.borrow()[i], 1);
assert_eq!(v.borrow().as_slice()[i+100], 1); assert_eq!(v.borrow()[i+100], 1);
} }
}); });
} }
DROP_VECTOR.with(|v| { DROP_VECTOR.with(|v| {
for i in range(0u, 200) { 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| { DROP_VECTOR.with(|v| {
for i in range(0u, 200) { 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| { DROP_VECTOR.with(|v| {
for i in range(0u, 200) { 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| { DROP_VECTOR.with(|v| {
for i in range(0u, 200) { 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| { DROP_VECTOR.with(|v| {
let nk = range(0u, 100).filter(|&i| { let nk = range(0u, 100).filter(|&i| {
v.borrow().as_slice()[i] == 1 v.borrow()[i] == 1
}).count(); }).count();
let nv = range(0u, 100).filter(|&i| { let nv = range(0u, 100).filter(|&i| {
v.borrow().as_slice()[i+100] == 1 v.borrow()[i+100] == 1
}).count(); }).count();
assert_eq!(nk, 50); assert_eq!(nk, 50);
@ -1654,7 +1654,7 @@ mod test_map {
DROP_VECTOR.with(|v| { DROP_VECTOR.with(|v| {
for i in range(0u, 200) { for i in range(0u, 200) {
assert_eq!(v.borrow().as_slice()[i], 0); assert_eq!(v.borrow()[i], 0);
} }
}); });
} }

View File

@ -827,7 +827,7 @@ mod test_set {
}; };
let v = hs.into_iter().collect::<Vec<char>>(); 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] #[test]

View File

@ -449,30 +449,30 @@ mod test {
let nread = reader.read(&mut buf); let nread = reader.read(&mut buf);
assert_eq!(Ok(3), nread); assert_eq!(Ok(3), nread);
let b: &[_] = &[5, 6, 7]; let b: &[_] = &[5, 6, 7];
assert_eq!(buf.as_slice(), b); assert_eq!(buf, b);
let mut buf = [0, 0]; let mut buf = [0, 0];
let nread = reader.read(&mut buf); let nread = reader.read(&mut buf);
assert_eq!(Ok(2), nread); assert_eq!(Ok(2), nread);
let b: &[_] = &[0, 1]; let b: &[_] = &[0, 1];
assert_eq!(buf.as_slice(), b); assert_eq!(buf, b);
let mut buf = [0]; let mut buf = [0];
let nread = reader.read(&mut buf); let nread = reader.read(&mut buf);
assert_eq!(Ok(1), nread); assert_eq!(Ok(1), nread);
let b: &[_] = &[2]; let b: &[_] = &[2];
assert_eq!(buf.as_slice(), b); assert_eq!(buf, b);
let mut buf = [0, 0, 0]; let mut buf = [0, 0, 0];
let nread = reader.read(&mut buf); let nread = reader.read(&mut buf);
assert_eq!(Ok(1), nread); assert_eq!(Ok(1), nread);
let b: &[_] = &[3, 0, 0]; let b: &[_] = &[3, 0, 0];
assert_eq!(buf.as_slice(), b); assert_eq!(buf, b);
let nread = reader.read(&mut buf); let nread = reader.read(&mut buf);
assert_eq!(Ok(1), nread); assert_eq!(Ok(1), nread);
let b: &[_] = &[4, 0, 0]; let b: &[_] = &[4, 0, 0];
assert_eq!(buf.as_slice(), b); assert_eq!(buf, b);
assert!(reader.read(&mut buf).is_err()); assert!(reader.read(&mut buf).is_err());
} }

View File

@ -176,28 +176,28 @@ mod test {
assert_eq!(Ok(3), reader.read(&mut buf)); assert_eq!(Ok(3), reader.read(&mut buf));
let a: &[u8] = &[1,2,3]; let a: &[u8] = &[1,2,3];
assert_eq!(a, buf.as_slice()); assert_eq!(a, buf);
assert_eq!(Ok(3), reader.read(&mut buf)); assert_eq!(Ok(3), reader.read(&mut buf));
let a: &[u8] = &[4,5,6]; let a: &[u8] = &[4,5,6];
assert_eq!(a, buf.as_slice()); assert_eq!(a, buf);
assert_eq!(Ok(2), reader.read(&mut buf)); assert_eq!(Ok(2), reader.read(&mut buf));
let a: &[u8] = &[7,8,6]; let a: &[u8] = &[7,8,6];
assert_eq!(a, buf.as_slice()); assert_eq!(a, buf);
match reader.read(buf.as_mut_slice()) { match reader.read(buf.as_mut_slice()) {
Ok(..) => panic!(), Ok(..) => panic!(),
Err(e) => assert_eq!(e.kind, io::EndOfFile), 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. // Ensure it continues to panic in the same way.
match reader.read(buf.as_mut_slice()) { match reader.read(buf.as_mut_slice()) {
Ok(..) => panic!(), Ok(..) => panic!(),
Err(e) => assert_eq!(e.kind, io::EndOfFile), Err(e) => assert_eq!(e.kind, io::EndOfFile),
} }
assert_eq!(a, buf.as_slice()); assert_eq!(a, buf);
} }
#[test] #[test]

View File

@ -837,7 +837,7 @@ mod test {
macro_rules! error( ($e:expr, $s:expr) => ( macro_rules! error( ($e:expr, $s:expr) => (
match $e { match $e {
Ok(_) => panic!("Unexpected success. Should've been: {}", $s), 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)) format!("`{}` did not contain `{}`", err, $s))
} }
) ) ) )
@ -995,7 +995,7 @@ mod test {
} }
check!(unlink(filename)); check!(unlink(filename));
let read_str = str::from_utf8(&read_mem).unwrap(); let read_str = str::from_utf8(&read_mem).unwrap();
assert!(read_str.as_slice() == final_msg.as_slice()); assert!(read_str == final_msg);
} }
#[test] #[test]
@ -1103,7 +1103,7 @@ mod test {
let f = dir.join(format!("{}.txt", n)); let f = dir.join(format!("{}.txt", n));
let mut w = check!(File::create(&f)); let mut w = check!(File::create(&f));
let msg_str = format!("{}{}", prefix, n.to_string()); 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)); check!(w.write(msg));
} }
let files = check!(readdir(dir)); let files = check!(readdir(dir));

View File

@ -444,7 +444,7 @@ mod test {
assert_eq!(writer.write(&[10]).unwrap_err().kind, io::EndOfFile); assert_eq!(writer.write(&[10]).unwrap_err().kind, io::EndOfFile);
} }
let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8]; let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8];
assert_eq!(buf.as_slice(), b); assert_eq!(buf, b);
} }
#[test] #[test]
@ -473,7 +473,7 @@ mod test {
} }
let b: &[_] = &[1, 3, 2, 0, 0, 0, 0, 4]; let b: &[_] = &[1, 3, 2, 0, 0, 0, 0, 4];
assert_eq!(buf.as_slice(), b); assert_eq!(buf, b);
} }
#[test] #[test]
@ -498,12 +498,12 @@ mod test {
assert_eq!(reader.read(&mut buf), Ok(1)); assert_eq!(reader.read(&mut buf), Ok(1));
assert_eq!(reader.tell(), Ok(1)); assert_eq!(reader.tell(), Ok(1));
let b: &[_] = &[0]; let b: &[_] = &[0];
assert_eq!(buf.as_slice(), b); assert_eq!(buf, b);
let mut buf = [0, ..4]; let mut buf = [0, ..4];
assert_eq!(reader.read(&mut buf), Ok(4)); assert_eq!(reader.read(&mut buf), Ok(4));
assert_eq!(reader.tell(), Ok(5)); assert_eq!(reader.tell(), Ok(5));
let b: &[_] = &[1, 2, 3, 4]; let b: &[_] = &[1, 2, 3, 4];
assert_eq!(buf.as_slice(), b); assert_eq!(buf, b);
assert_eq!(reader.read(&mut buf), Ok(3)); assert_eq!(reader.read(&mut buf), Ok(3));
let b: &[_] = &[5, 6, 7]; let b: &[_] = &[5, 6, 7];
assert_eq!(buf[0..3], b); assert_eq!(buf[0..3], b);
@ -551,12 +551,12 @@ mod test {
assert_eq!(reader.read(&mut buf), Ok(1)); assert_eq!(reader.read(&mut buf), Ok(1));
assert_eq!(reader.tell(), Ok(1)); assert_eq!(reader.tell(), Ok(1));
let b: &[_] = &[0]; let b: &[_] = &[0];
assert_eq!(buf.as_slice(), b); assert_eq!(buf, b);
let mut buf = [0, ..4]; let mut buf = [0, ..4];
assert_eq!(reader.read(&mut buf), Ok(4)); assert_eq!(reader.read(&mut buf), Ok(4));
assert_eq!(reader.tell(), Ok(5)); assert_eq!(reader.tell(), Ok(5));
let b: &[_] = &[1, 2, 3, 4]; let b: &[_] = &[1, 2, 3, 4];
assert_eq!(buf.as_slice(), b); assert_eq!(buf, b);
assert_eq!(reader.read(&mut buf), Ok(3)); assert_eq!(reader.read(&mut buf), Ok(3));
let b: &[_] = &[5, 6, 7]; let b: &[_] = &[5, 6, 7];
assert_eq!(buf[0..3], b); assert_eq!(buf[0..3], b);
@ -652,15 +652,15 @@ mod test {
let mut buf = [0, ..3]; let mut buf = [0, ..3];
assert!(r.read_at_least(buf.len(), &mut buf).is_ok()); assert!(r.read_at_least(buf.len(), &mut buf).is_ok());
let b: &[_] = &[1, 2, 3]; 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!(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()); assert!(r.read_at_least(buf.len(), &mut buf).is_ok());
let b: &[_] = &[4, 5, 6]; 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()); assert!(r.read_at_least(buf.len(), &mut buf).is_err());
let b: &[_] = &[7, 8, 6]; 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) { fn do_bench_mem_writer(b: &mut Bencher, times: uint, len: uint) {
@ -757,7 +757,7 @@ mod test {
for _i in range(0u, 10) { for _i in range(0u, 10) {
let mut buf = [0 as u8, .. 10]; let mut buf = [0 as u8, .. 10];
rdr.read(&mut buf).unwrap(); rdr.read(&mut buf).unwrap();
assert_eq!(buf.as_slice(), [5, .. 10].as_slice()); assert_eq!(buf, [5, .. 10]);
} }
} }
}); });

View File

@ -238,8 +238,8 @@ use os;
use boxed::Box; use boxed::Box;
use result::{Ok, Err, Result}; use result::{Ok, Err, Result};
use sys; use sys;
use slice::{AsSlice, SlicePrelude}; use slice::SlicePrelude;
use str::{Str, StrPrelude}; use str::StrPrelude;
use str; use str;
use string::String; use string::String;
use uint; use uint;
@ -316,7 +316,7 @@ impl IoError {
pub fn from_errno(errno: uint, detail: bool) -> IoError { pub fn from_errno(errno: uint, detail: bool) -> IoError {
let mut err = sys::decode_error(errno as i32); let mut err = sys::decode_error(errno as i32);
if detail && err.kind == OtherIoError { 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()) .map(|c| c.to_lowercase()).collect())
} }
err err

View File

@ -236,8 +236,8 @@ impl Command {
// if the env is currently just inheriting from the parent's, // if the env is currently just inheriting from the parent's,
// materialize the parent's env into a hashtable. // materialize the parent's env into a hashtable.
self.env = Some(os::env_as_bytes().into_iter() self.env = Some(os::env_as_bytes().into_iter()
.map(|(k, v)| (EnvKey(k.as_slice().to_c_str()), .map(|(k, v)| (EnvKey(k.to_c_str()),
v.as_slice().to_c_str())) v.to_c_str()))
.collect()); .collect());
self.env.as_mut().unwrap() self.env.as_mut().unwrap()
} }
@ -973,7 +973,7 @@ mod tests {
let output = String::from_utf8(prog.wait_with_output().unwrap().output).unwrap(); let output = String::from_utf8(prog.wait_with_output().unwrap().output).unwrap();
let parent_dir = os::getcwd().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 parent_stat = parent_dir.stat().unwrap();
let child_stat = child_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 prog = pwd_cmd().cwd(&parent_dir).spawn().unwrap();
let output = String::from_utf8(prog.wait_with_output().unwrap().output).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 parent_stat = parent_dir.stat().unwrap();
let child_stat = child_dir.stat().unwrap(); let child_stat = child_dir.stat().unwrap();
@ -1031,8 +1031,7 @@ mod tests {
for &(ref k, ref v) in r.iter() { for &(ref k, ref v) in r.iter() {
// don't check windows magical empty-named variables // don't check windows magical empty-named variables
assert!(k.is_empty() || assert!(k.is_empty() ||
output.as_slice() output.contains(format!("{}={}", *k, *v).as_slice()),
.contains(format!("{}={}", *k, *v).as_slice()),
"output doesn't contain `{}={}`\n{}", "output doesn't contain `{}={}`\n{}",
k, v, output); k, v, output);
} }
@ -1050,12 +1049,10 @@ mod tests {
for &(ref k, ref v) in r.iter() { for &(ref k, ref v) in r.iter() {
// don't check android RANDOM variables // don't check android RANDOM variables
if *k != "RANDOM".to_string() { if *k != "RANDOM".to_string() {
assert!(output.as_slice() assert!(output..contains(format!("{}={}",
.contains(format!("{}={}",
*k, *k,
*v).as_slice()) || *v).as_slice()) ||
output.as_slice() output..contains(format!("{}=\'{}\'",
.contains(format!("{}=\'{}\'",
*k, *k,
*v).as_slice())); *v).as_slice()));
} }
@ -1084,7 +1081,7 @@ mod tests {
let result = prog.wait_with_output().unwrap(); let result = prog.wait_with_output().unwrap();
let output = String::from_utf8_lossy(result.output.as_slice()).into_string(); 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); "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 result = prog.wait_with_output().unwrap();
let output = String::from_utf8_lossy(result.output.as_slice()).into_string(); 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); "didn't find RUN_TEST_NEW_ENV inside of:\n\n{}", output);
} }

View File

@ -542,6 +542,6 @@ mod tests {
panic!("my special message"); panic!("my special message");
}); });
let s = r.read_to_string().unwrap(); let s = r.read_to_string().unwrap();
assert!(s.as_slice().contains("my special message")); assert!(s.contains("my special message"));
} }
} }

View File

@ -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>)> { fn env_convert(input: Vec<Vec<u8>>) -> Vec<(Vec<u8>, Vec<u8>)> {
let mut pairs = Vec::new(); let mut pairs = Vec::new();
for p in input.iter() { 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 key = it.next().unwrap().to_vec();
let default: &[u8] = &[]; let default: &[u8] = &[];
let val = it.next().unwrap_or(default).to_vec(); let val = it.next().unwrap_or(default).to_vec();
@ -2066,7 +2066,7 @@ mod tests {
#[cfg(unix)] #[cfg(unix)]
fn join_paths_unix() { fn join_paths_unix() {
fn test_eq(input: &[&str], output: &str) -> bool { 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(&[], "")); assert!(test_eq(&[], ""));
@ -2081,7 +2081,7 @@ mod tests {
#[cfg(windows)] #[cfg(windows)]
fn join_paths_windows() { fn join_paths_windows() {
fn test_eq(input: &[&str], output: &str) -> bool { 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(&[], "")); assert!(test_eq(&[], ""));

View File

@ -941,6 +941,6 @@ mod tests {
let input = r"\foo\bar\baz"; let input = r"\foo\bar\baz";
let path: WindowsPath = WindowsPath::new(input.to_c_str()); 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);
} }
} }

View File

@ -131,7 +131,7 @@ impl GenericPathUnsafe for Path {
unsafe fn set_filename_unchecked<T: BytesContainer>(&mut self, filename: T) { unsafe fn set_filename_unchecked<T: BytesContainer>(&mut self, filename: T) {
let filename = filename.container_as_bytes(); let filename = filename.container_as_bytes();
match self.sepidx { match self.sepidx {
None if b".." == self.repr.as_slice() => { None if b".." == self.repr => {
let mut v = Vec::with_capacity(3 + filename.len()); let mut v = Vec::with_capacity(3 + filename.len());
v.push_all(dot_dot_static); v.push_all(dot_dot_static);
v.push(SEP_BYTE); v.push(SEP_BYTE);
@ -158,7 +158,7 @@ impl GenericPathUnsafe for Path {
self.repr = Path::normalize(v.as_slice()); 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) { unsafe fn push_unchecked<T: BytesContainer>(&mut self, path: T) {
@ -174,7 +174,7 @@ impl GenericPathUnsafe for Path {
// FIXME: this is slow // FIXME: this is slow
self.repr = Path::normalize(v.as_slice()); 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] { fn dirname<'a>(&'a self) -> &'a [u8] {
match self.sepidx { 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, None => dot_static,
Some(0) => self.repr[..1], Some(0) => self.repr[..1],
Some(idx) if self.repr[idx+1..] == b".." => self.repr.as_slice(), 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]> { fn filename<'a>(&'a self) -> Option<&'a [u8]> {
match self.sepidx { match self.sepidx {
None if b"." == self.repr.as_slice() || None if b"." == self.repr ||
b".." == self.repr.as_slice() => None, b".." == self.repr => None,
None => Some(self.repr.as_slice()), None => Some(self.repr.as_slice()),
Some(idx) if self.repr[idx+1..] == b".." => None, Some(idx) if self.repr[idx+1..] == b".." => None,
Some(0) if self.repr[1..].is_empty() => None, Some(0) if self.repr[1..].is_empty() => None,
@ -212,20 +212,20 @@ impl GenericPath for Path {
fn pop(&mut self) -> bool { fn pop(&mut self) -> bool {
match self.sepidx { match self.sepidx {
None if b"." == self.repr.as_slice() => false, None if b"." == self.repr => false,
None => { None => {
self.repr = vec![b'.']; self.repr = vec![b'.'];
self.sepidx = None; self.sepidx = None;
true true
} }
Some(0) if b"/" == self.repr.as_slice() => false, Some(0) if b"/" == self.repr => false,
Some(idx) => { Some(idx) => {
if idx == 0 { if idx == 0 {
self.repr.truncate(idx+1); self.repr.truncate(idx+1);
} else { } else {
self.repr.truncate(idx); self.repr.truncate(idx);
} }
self.sepidx = self.repr.as_slice().rposition_elem(&SEP_BYTE); self.sepidx = self.repr.rposition_elem(&SEP_BYTE);
true true
} }
} }
@ -250,7 +250,7 @@ impl GenericPath for Path {
} else { } else {
let mut ita = self.components(); let mut ita = self.components();
let mut itb = other.components(); let mut itb = other.components();
if b"." == self.repr.as_slice() { if b"." == self.repr {
return match itb.next() { return match itb.next() {
None => true, None => true,
Some(b) => b != b".." 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 // None result means the byte vector didn't need normalizing
fn normalize_helper<'a>(v: &'a [u8], is_abs: bool) -> Option<Vec<&'a [u8]>> { 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; return None;
} }
let mut comps: Vec<&'a [u8]> = vec![]; let mut comps: Vec<&'a [u8]> = vec![];
@ -495,8 +495,8 @@ mod tests {
t!(s: Path::new("foo/../../.."), "../.."); t!(s: Path::new("foo/../../.."), "../..");
t!(s: Path::new("foo/../../bar"), "../bar"); 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(), b"foo/bar");
assert_eq!(Path::new(b"/foo/../../bar").into_vec().as_slice(), assert_eq!(Path::new(b"/foo/../../bar").into_vec(),
b"/bar"); b"/bar");
let p = Path::new(b"foo/bar\x80"); let p = Path::new(b"foo/bar\x80");
@ -536,7 +536,7 @@ mod tests {
($path:expr, $disp:ident, $exp:expr) => ( ($path:expr, $disp:ident, $exp:expr) => (
{ {
let path = Path::new($path); 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 path = Path::new($path);
let f = format!("{}", path.display()); let f = format!("{}", path.display());
assert!(f.as_slice() == $exp); assert!(f == $exp);
let f = format!("{}", path.filename_display()); 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 path = Path::new($arg);
let comps = path.components().collect::<Vec<&[u8]>>(); let comps = path.components().collect::<Vec<&[u8]>>();
let exp: &[&[u8]] = &[$($exp),*]; let exp: &[&[u8]] = &[$($exp),*];
assert_eq!(comps.as_slice(), exp); assert_eq!(comps, exp);
let comps = path.components().rev().collect::<Vec<&[u8]>>(); let comps = path.components().rev().collect::<Vec<&[u8]>>();
let exp = exp.iter().rev().map(|&x|x).collect::<Vec<&[u8]>>(); let exp = exp.iter().rev().map(|&x|x).collect::<Vec<&[u8]>>();
assert_eq!(comps, exp) assert_eq!(comps, exp)
@ -1211,7 +1211,7 @@ mod tests {
let path = Path::new($arg); let path = Path::new($arg);
let comps = path.str_components().collect::<Vec<Option<&str>>>(); let comps = path.str_components().collect::<Vec<Option<&str>>>();
let exp: &[Option<&str>] = &$exp; 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 comps = path.str_components().rev().collect::<Vec<Option<&str>>>();
let exp = exp.iter().rev().map(|&x|x).collect::<Vec<Option<&str>>>(); let exp = exp.iter().rev().map(|&x|x).collect::<Vec<Option<&str>>>();
assert_eq!(comps, exp); assert_eq!(comps, exp);

View File

@ -181,7 +181,7 @@ impl GenericPathUnsafe for Path {
unsafe fn set_filename_unchecked<T: BytesContainer>(&mut self, filename: T) { unsafe fn set_filename_unchecked<T: BytesContainer>(&mut self, filename: T) {
let filename = filename.container_as_str().unwrap(); let filename = filename.container_as_str().unwrap();
match self.sepidx_or_prefix_len() { 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()); let mut s = String::with_capacity(3 + filename.len());
s.push_str(".."); s.push_str("..");
s.push(SEP); s.push(SEP);
@ -191,22 +191,22 @@ impl GenericPathUnsafe for Path {
None => { None => {
self.update_normalized(filename); 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()); 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(SEP);
s.push_str(filename); s.push_str(filename);
self.update_normalized(s); self.update_normalized(s);
} }
Some((idxb,idxa,_)) if self.prefix == Some(DiskPrefix) && idxa == self.prefix_len() => { Some((idxb,idxa,_)) if self.prefix == Some(DiskPrefix) && idxa == self.prefix_len() => {
let mut s = String::with_capacity(idxb + filename.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); s.push_str(filename);
self.update_normalized(s); self.update_normalized(s);
} }
Some((idxb,_,_)) => { Some((idxb,_,_)) => {
let mut s = String::with_capacity(idxb + 1 + filename.len()); 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(SEP);
s.push_str(filename); s.push_str(filename);
self.update_normalized(s); self.update_normalized(s);
@ -355,21 +355,21 @@ impl GenericPath for Path {
/// Always returns a `Some` value. /// Always returns a `Some` value.
fn dirname_str<'a>(&'a self) -> Option<&'a str> { fn dirname_str<'a>(&'a self) -> Option<&'a str> {
Some(match self.sepidx_or_prefix_len() { 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 => ".", 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() 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() 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,_)) => { Some((idxb,idxa,_)) => {
match self.prefix { match self.prefix {
Some(DiskPrefix) | Some(VerbatimDiskPrefix) if idxb == self.prefix_len() => { 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] #[inline]
fn pop(&mut self) -> bool { fn pop(&mut self) -> bool {
match self.sepidx_or_prefix_len() { match self.sepidx_or_prefix_len() {
None if "." == self.repr.as_slice() => false, None if "." == self.repr => false,
None => { None => {
self.repr = String::from_str("."); self.repr = String::from_str(".");
self.sepidx = None; self.sepidx = None;
true true
} }
Some((idxb,idxa,end)) if idxb == idxa && idxb == end => false, 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,_)) => { Some((idxb,idxa,_)) => {
let trunc = match self.prefix { let trunc = match self.prefix {
Some(DiskPrefix) | Some(VerbatimDiskPrefix) | None => { Some(DiskPrefix) | Some(VerbatimDiskPrefix) | None => {
@ -441,15 +441,15 @@ impl GenericPath for Path {
if self.prefix.is_some() { if self.prefix.is_some() {
Some(Path::new(match self.prefix { Some(Path::new(match self.prefix {
Some(DiskPrefix) if self.is_absolute() => { 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) => { 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) { } 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 { } else {
None None
} }
@ -468,7 +468,7 @@ impl GenericPath for Path {
fn is_absolute(&self) -> bool { fn is_absolute(&self) -> bool {
match self.prefix { match self.prefix {
Some(DiskPrefix) => { 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 rest.len() > 0 && rest.as_bytes()[0] == SEP_BYTE
} }
Some(_) => true, Some(_) => true,
@ -490,7 +490,7 @@ impl GenericPath for Path {
} else { } else {
let mut ita = self.str_components().map(|x|x.unwrap()); let mut ita = self.str_components().map(|x|x.unwrap());
let mut itb = other.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(".."); return itb.next() != Some("..");
} }
loop { loop {
@ -826,7 +826,7 @@ impl Path {
fn update_sepidx(&mut self) { fn update_sepidx(&mut self) {
let s = if self.has_nonsemantic_trailing_slash() { 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() }; } else { self.repr.as_slice() };
let idx = s.rfind(if !prefix_is_verbatim(self.prefix) { is_sep } let idx = s.rfind(if !prefix_is_verbatim(self.prefix) { is_sep }
else { is_sep_verbatim }); else { is_sep_verbatim });
@ -922,7 +922,7 @@ pub fn make_non_verbatim(path: &Path) -> Option<Path> {
} }
// now ensure normalization didn't change anything // now ensure normalization didn't change anything
if repr.slice_from(path.prefix_len()) == 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) Some(new_path)
} else { } else {
None None
@ -1232,8 +1232,8 @@ mod tests {
t!(s: Path::new("foo\\..\\..\\.."), "..\\.."); t!(s: Path::new("foo\\..\\..\\.."), "..\\..");
t!(s: Path::new("foo\\..\\..\\bar"), "..\\bar"); 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(), 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"\\bar");
t!(s: Path::new("\\\\a"), "\\a"); t!(s: Path::new("\\\\a"), "\\a");
t!(s: Path::new("\\\\a\\"), "\\a"); t!(s: Path::new("\\\\a\\"), "\\a");
@ -1340,9 +1340,9 @@ mod tests {
{ {
let path = Path::new($path); let path = Path::new($path);
let f = format!("{}", path.display()); let f = format!("{}", path.display());
assert_eq!(f.as_slice(), $exp); assert_eq!(f, $exp);
let f = format!("{}", path.filename_display()); 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()) let comps = path.str_components().map(|x|x.unwrap())
.collect::<Vec<&str>>(); .collect::<Vec<&str>>();
let exp: &[&str] = &$exp; let exp: &[&str] = &$exp;
assert_eq!(comps.as_slice(), exp); assert_eq!(comps, exp);
let comps = path.str_components().rev().map(|x|x.unwrap()) let comps = path.str_components().rev().map(|x|x.unwrap())
.collect::<Vec<&str>>(); .collect::<Vec<&str>>();
let exp = exp.iter().rev().map(|&x|x).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 path = Path::new($path);
let comps = path.components().collect::<Vec<&[u8]>>(); let comps = path.components().collect::<Vec<&[u8]>>();
let exp: &[&[u8]] = &$exp; let exp: &[&[u8]] = &$exp;
assert_eq!(comps.as_slice(), exp); assert_eq!(comps, exp);
let comps = path.components().rev().collect::<Vec<&[u8]>>(); let comps = path.components().rev().collect::<Vec<&[u8]>>();
let exp = exp.iter().rev().map(|&x|x).collect::<Vec<&[u8]>>(); let exp = exp.iter().rev().map(|&x|x).collect::<Vec<&[u8]>>();
assert_eq!(comps, exp); assert_eq!(comps, exp);

View File

@ -529,7 +529,7 @@ mod test {
let mut one = [1i]; let mut one = [1i];
r.shuffle(&mut one); r.shuffle(&mut one);
let b: &[_] = &[1]; let b: &[_] = &[1];
assert_eq!(one.as_slice(), b); assert_eq!(one, b);
let mut two = [1i, 2]; let mut two = [1i, 2];
r.shuffle(&mut two); r.shuffle(&mut two);
@ -538,7 +538,7 @@ mod test {
let mut x = [1i, 1, 1]; let mut x = [1i, 1, 1];
r.shuffle(&mut x); r.shuffle(&mut x);
let b: &[_] = &[1, 1, 1]; let b: &[_] = &[1, 1, 1];
assert_eq!(x.as_slice(), b); assert_eq!(x, b);
} }
#[test] #[test]
@ -548,7 +548,7 @@ mod test {
let mut v = [1i, 1, 1]; let mut v = [1i, 1, 1];
r.shuffle(&mut v); r.shuffle(&mut v);
let b: &[_] = &[1, 1, 1]; let b: &[_] = &[1, 1, 1];
assert_eq!(v.as_slice(), b); assert_eq!(v, b);
assert_eq!(r.gen_range(0u, 1u), 0u); assert_eq!(r.gen_range(0u, 1u), 0u);
} }

View File

@ -376,8 +376,8 @@ pub fn readlink(p: &Path) -> IoResult<Path> {
libc::VOLUME_NAME_DOS) libc::VOLUME_NAME_DOS)
}); });
let ret = match ret { let ret = match ret {
Some(ref s) if s.as_slice().starts_with(r"\\?\") => { // " Some(ref s) if s.starts_with(r"\\?\") => { // "
Ok(Path::new(s.as_slice().slice_from(4))) Ok(Path::new(s.slice_from(4)))
} }
Some(s) => Ok(Path::new(s)), Some(s) => Ok(Path::new(s)),
None => Err(super::last_error()), None => Err(super::last_error()),

View File

@ -223,7 +223,7 @@ impl Process {
with_envp(cfg.env(), |envp| { with_envp(cfg.env(), |envp| {
with_dirp(cfg.cwd(), |dirp| { 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); cmd_str.push(0);
let created = CreateProcessW(ptr::null(), let created = CreateProcessW(ptr::null(),
cmd_str.as_mut_ptr(), cmd_str.as_mut_ptr(),
@ -433,7 +433,7 @@ fn with_envp<K, V, T>(env: Option<&collections::HashMap<K, V>>,
let kv = format!("{}={}", let kv = format!("{}={}",
pair.ref0().container_as_str().unwrap(), pair.ref0().container_as_str().unwrap(),
pair.ref1().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); blk.push(0);
} }

View File

@ -113,7 +113,7 @@ impl TTY {
pub fn write(&mut self, buf: &[u8]) -> IoResult<()> { pub fn write(&mut self, buf: &[u8]) -> IoResult<()> {
let utf16 = match from_utf8(buf) { let utf16 = match from_utf8(buf) {
Some(utf8) => { Some(utf8) => {
utf8.as_slice().utf16_units().collect::<Vec<u16>>() utf8.utf16_units().collect::<Vec<u16>>()
} }
None => return Err(invalid_encoding()), None => return Err(invalid_encoding()),
}; };

View File

@ -54,7 +54,7 @@ use result::Result;
use rustrt::local::Local; use rustrt::local::Local;
use rustrt::task::Task; use rustrt::task::Task;
use rustrt::task; use rustrt::task;
use str::{Str, SendStr}; use str::SendStr;
use string::{String, ToString}; use string::{String, ToString};
use sync::Future; use sync::Future;
@ -242,7 +242,7 @@ pub fn name() -> Option<String> {
let task = Local::borrow(None::<Task>); let task = Local::borrow(None::<Task>);
match task.name { match task.name {
Some(ref name) => Some(name.as_slice().to_string()), Some(ref name) => Some(name.to_string()),
None => None None => None
} }
} }