diff options
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/ffi/c_str.rs | 17 | ||||
| -rw-r--r-- | src/libstd/io/buffered.rs | 4 | ||||
| -rw-r--r-- | src/libstd/io/cursor.rs | 17 | ||||
| -rw-r--r-- | src/libstd/old_io/util.rs | 3 | ||||
| -rw-r--r-- | src/libstd/old_path/mod.rs | 20 | ||||
| -rw-r--r-- | src/libstd/old_path/posix.rs | 30 | ||||
| -rw-r--r-- | src/libstd/old_path/windows.rs | 12 |
7 files changed, 79 insertions, 24 deletions
diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 48526f2bf2d..1591a9d4d29 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -451,6 +451,23 @@ impl IntoBytes for Vec<u8> { fn into_bytes(self) -> Vec<u8> { self } } +macro_rules! array_impls { + ($($N: expr)+) => { + $( + impl<'a> IntoBytes for &'a [u8; $N] { + fn into_bytes(self) -> Vec<u8> { self.to_vec() } + } + )+ + } +} + +array_impls! { + 0 1 2 3 4 5 6 7 8 9 + 10 11 12 13 14 15 16 17 18 19 + 20 21 22 23 24 25 26 27 28 29 + 30 31 32 +} + #[cfg(test)] mod tests { use prelude::v1::*; diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index 73dcf058e45..43eec695274 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -622,7 +622,7 @@ mod tests { #[test] fn test_read_line() { - let in_buf = b"a\nb\nc"; + let in_buf: &[u8] = b"a\nb\nc"; let mut reader = BufReader::with_capacity(2, in_buf); let mut s = String::new(); reader.read_line(&mut s).unwrap(); @@ -640,7 +640,7 @@ mod tests { #[test] fn test_lines() { - let in_buf = b"a\nb\nc"; + let in_buf: &[u8] = b"a\nb\nc"; let reader = BufReader::with_capacity(2, in_buf); let mut it = reader.lines(); assert_eq!(it.next(), Some(Ok("a".to_string()))); diff --git a/src/libstd/io/cursor.rs b/src/libstd/io/cursor.rs index 2445f5a7a40..bfcea75ad6a 100644 --- a/src/libstd/io/cursor.rs +++ b/src/libstd/io/cursor.rs @@ -129,6 +129,23 @@ impl<'a> BufRead for Cursor<&'a mut [u8]> { buffer!(); } #[stable(feature = "rust1", since = "1.0.0")] impl<'a> BufRead for Cursor<Vec<u8>> { buffer!(); } +macro_rules! array_impls { + ($($N: expr)+) => { + $( + impl<'a> io::Seek for Cursor<&'a [u8; $N]> { seek!(); } + impl<'a> Read for Cursor<&'a [u8; $N]> { read!(); } + impl<'a> BufRead for Cursor<&'a [u8; $N]> { buffer!(); } + )+ + } +} + +array_impls! { + 0 1 2 3 4 5 6 7 8 9 + 10 11 12 13 14 15 16 17 18 19 + 20 21 22 23 24 25 26 27 28 29 + 30 31 32 +} + #[stable(feature = "rust1", since = "1.0.0")] impl<'a> Write for Cursor<&'a mut [u8]> { fn write(&mut self, data: &[u8]) -> io::Result<usize> { diff --git a/src/libstd/old_io/util.rs b/src/libstd/old_io/util.rs index 4faf8af57b4..413184c84d2 100644 --- a/src/libstd/old_io/util.rs +++ b/src/libstd/old_io/util.rs @@ -445,7 +445,8 @@ mod test { #[test] fn limit_reader_buffer() { - let r = &mut b"0123456789\n0123456789\n"; + let mut r: &[u8] = b"0123456789\n0123456789\n"; + let r = &mut r; { let mut r = LimitReader::new(r.by_ref(), 3); assert_eq!(r.read_line(), Ok("012".to_string())); diff --git a/src/libstd/old_path/mod.rs b/src/libstd/old_path/mod.rs index 37875658ae0..cb7ee36183d 100644 --- a/src/libstd/old_path/mod.rs +++ b/src/libstd/old_path/mod.rs @@ -895,6 +895,26 @@ impl BytesContainer for [u8] { } } +macro_rules! array_impls { + ($($N: expr)+) => { + $( + impl BytesContainer for [u8; $N] { + #[inline] + fn container_as_bytes(&self) -> &[u8] { + &self[..] + } + } + )+ + } +} + +array_impls! { + 0 1 2 3 4 5 6 7 8 9 + 10 11 12 13 14 15 16 17 18 19 + 20 21 22 23 24 25 26 27 28 29 + 30 31 32 +} + impl BytesContainer for Vec<u8> { #[inline] fn container_as_bytes(&self) -> &[u8] { diff --git a/src/libstd/old_path/posix.rs b/src/libstd/old_path/posix.rs index e35623d7b1a..263e8bf0570 100644 --- a/src/libstd/old_path/posix.rs +++ b/src/libstd/old_path/posix.rs @@ -632,9 +632,9 @@ mod tests { ); } - t!(v: b"a/b/c", filename, Some(b"c")); - t!(v: b"a/b/c\xFF", filename, Some(b"c\xFF")); - t!(v: b"a/b\xFF/c", filename, Some(b"c")); + t!(v: b"a/b/c", filename, Some(&b"c"[..])); + t!(v: b"a/b/c\xFF", filename, Some(&b"c\xFF"[..])); + t!(v: b"a/b\xFF/c", filename, Some(&b"c"[..])); t!(s: "a/b/c", filename, Some("c"), opt); t!(s: "/a/b/c", filename, Some("c"), opt); t!(s: "a", filename, Some("a"), opt); @@ -656,9 +656,9 @@ mod tests { t!(s: "..", dirname, ".."); t!(s: "../..", dirname, "../.."); - t!(v: b"hi/there.txt", filestem, Some(b"there")); - t!(v: b"hi/there\x80.txt", filestem, Some(b"there\x80")); - t!(v: b"hi/there.t\x80xt", filestem, Some(b"there")); + t!(v: b"hi/there.txt", filestem, Some(&b"there"[..])); + t!(v: b"hi/there\x80.txt", filestem, Some(&b"there\x80"[..])); + t!(v: b"hi/there.t\x80xt", filestem, Some(&b"there"[..])); t!(s: "hi/there.txt", filestem, Some("there"), opt); t!(s: "hi/there", filestem, Some("there"), opt); t!(s: "there.txt", filestem, Some("there"), opt); @@ -672,9 +672,9 @@ mod tests { t!(s: "..", filestem, None, opt); t!(s: "../..", filestem, None, opt); - t!(v: b"hi/there.txt", extension, Some(b"txt")); - t!(v: b"hi/there\x80.txt", extension, Some(b"txt")); - t!(v: b"hi/there.t\x80xt", extension, Some(b"t\x80xt")); + t!(v: b"hi/there.txt", extension, Some(&b"txt"[..])); + t!(v: b"hi/there\x80.txt", extension, Some(&b"txt"[..])); + t!(v: b"hi/there.t\x80xt", extension, Some(&b"t\x80xt"[..])); t!(v: b"hi/there", extension, None); t!(v: b"hi/there\x80", extension, None); t!(s: "hi/there.txt", extension, Some("txt"), opt); @@ -756,8 +756,8 @@ mod tests { t!(s: "a/b/c", ["d", "/e"], "/e"); t!(s: "a/b/c", ["d", "/e", "f"], "/e/f"); t!(s: "a/b/c", ["d".to_string(), "e".to_string()], "a/b/c/d/e"); - t!(v: b"a/b/c", [b"d", b"e"], b"a/b/c/d/e"); - t!(v: b"a/b/c", [b"d", b"/e", b"f"], b"/e/f"); + t!(v: b"a/b/c", [&b"d"[..], &b"e"[..]], b"a/b/c/d/e"); + t!(v: b"a/b/c", [&b"d"[..], &b"/e"[..], &b"f"[..]], b"/e/f"); t!(v: b"a/b/c", [b"d".to_vec(), b"e".to_vec()], b"a/b/c/d/e"); } @@ -983,10 +983,10 @@ mod tests { ) } - t!(v: Path::new(b"a/b/c"), Some(b"c"), b"a/b", Some(b"c"), None); - t!(v: Path::new(b"a/b/\xFF"), Some(b"\xFF"), b"a/b", Some(b"\xFF"), None); - t!(v: Path::new(b"hi/there.\xFF"), Some(b"there.\xFF"), b"hi", - Some(b"there"), Some(b"\xFF")); + t!(v: Path::new(b"a/b/c"), Some(&b"c"[..]), b"a/b", Some(&b"c"[..]), None); + t!(v: Path::new(b"a/b/\xFF"), Some(&b"\xFF"[..]), b"a/b", Some(&b"\xFF"[..]), None); + t!(v: Path::new(b"hi/there.\xFF"), Some(&b"there.\xFF"[..]), b"hi", + Some(&b"there"[..]), Some(&b"\xFF"[..])); t!(s: Path::new("a/b/c"), Some("c"), Some("a/b"), Some("c"), None); t!(s: Path::new("."), None, Some("."), None, None); t!(s: Path::new("/"), None, Some("/"), None, None); diff --git a/src/libstd/old_path/windows.rs b/src/libstd/old_path/windows.rs index ff4f083333b..3199cf2fcac 100644 --- a/src/libstd/old_path/windows.rs +++ b/src/libstd/old_path/windows.rs @@ -1397,7 +1397,7 @@ mod tests { ) } - t!(v: b"a\\b\\c", filename, Some(b"c")); + t!(v: b"a\\b\\c", filename, Some(&b"c"[..])); t!(s: "a\\b\\c", filename_str, "c"); t!(s: "\\a\\b\\c", filename_str, "c"); t!(s: "a", filename_str, "a"); @@ -1461,7 +1461,7 @@ mod tests { t!(s: "\\\\.\\foo", dirname_str, "\\\\.\\foo"); t!(s: "\\\\?\\a\\b\\", dirname_str, "\\\\?\\a"); - t!(v: b"hi\\there.txt", filestem, Some(b"there")); + t!(v: b"hi\\there.txt", filestem, Some(&b"there"[..])); t!(s: "hi\\there.txt", filestem_str, "there"); t!(s: "hi\\there", filestem_str, "there"); t!(s: "there.txt", filestem_str, "there"); @@ -1476,7 +1476,7 @@ mod tests { t!(s: "..\\..", filestem_str, None, opt); // filestem is based on filename, so we don't need the full set of prefix tests - t!(v: b"hi\\there.txt", extension, Some(b"txt")); + t!(v: b"hi\\there.txt", extension, Some(&b"txt"[..])); t!(v: b"hi\\there", extension, None); t!(s: "hi\\there.txt", extension_str, Some("txt"), opt); t!(s: "hi\\there", extension_str, None, opt); @@ -1603,8 +1603,8 @@ mod tests { t!(s: "a\\b\\c", ["d", "\\e"], "\\e"); t!(s: "a\\b\\c", ["d", "\\e", "f"], "\\e\\f"); t!(s: "a\\b\\c", ["d".to_string(), "e".to_string()], "a\\b\\c\\d\\e"); - t!(v: b"a\\b\\c", [b"d", b"e"], b"a\\b\\c\\d\\e"); - t!(v: b"a\\b\\c", [b"d", b"\\e", b"f"], b"\\e\\f"); + t!(v: b"a\\b\\c", [&b"d"[..], &b"e"[..]], b"a\\b\\c\\d\\e"); + t!(v: b"a\\b\\c", [&b"d"[..], &b"\\e"[..], &b"f"[..]], b"\\e\\f"); t!(v: b"a\\b\\c", [b"d".to_vec(), b"e".to_vec()], b"a\\b\\c\\d\\e"); } @@ -1898,7 +1898,7 @@ mod tests { ) } - t!(v: Path::new(b"a\\b\\c"), Some(b"c"), b"a\\b", Some(b"c"), None); + t!(v: Path::new(b"a\\b\\c"), Some(&b"c"[..]), b"a\\b", Some(&b"c"[..]), None); t!(s: Path::new("a\\b\\c"), Some("c"), Some("a\\b"), Some("c"), None); t!(s: Path::new("."), None, Some("."), None, None); t!(s: Path::new("\\"), None, Some("\\"), None, None); |
