Auto merge of #22838 - petrochenkov:bytelit, r=alexcrichton

This patch changes the type of byte string literals from `&[u8]` to `&[u8; N]`.
It also implements some necessary traits (`IntoBytes`, `Seek`, `Read`, `BufRead`) for fixed-size arrays (also related to #21725) and adds test for #17233, which seems to be resolved.

Fixes #18465
[breaking-change]
This commit is contained in:
bors
2015-03-18 08:27:22 +00:00
21 changed files with 276 additions and 191 deletions

View File

@@ -23,10 +23,34 @@ use marker::{Copy, Sized};
use option::Option;
use slice::{Iter, IterMut, SliceExt};
/// Utility trait implemented only on arrays of fixed size
///
/// This trait can be used to implement other traits on fixed-size arrays
/// without causing much metadata bloat.
#[unstable(feature = "core")]
pub trait FixedSizeArray<T> {
/// Converts the array to immutable slice
fn as_slice(&self) -> &[T];
/// Converts the array to mutable slice
fn as_mut_slice(&mut self) -> &mut [T];
}
// macro for implementing n-ary tuple functions and operations
macro_rules! array_impls {
($($N:expr)+) => {
$(
#[unstable(feature = "core")]
impl<T> FixedSizeArray<T> for [T; $N] {
#[inline]
fn as_slice(&self) -> &[T] {
&self[..]
}
#[inline]
fn as_mut_slice(&mut self) -> &mut [T] {
&mut self[..]
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T:Copy> Clone for [T; $N] {
fn clone(&self) -> [T; $N] {

View File

@@ -129,6 +129,7 @@ pub mod default;
/* Core types and methods on primitives */
pub mod any;
pub mod array;
pub mod atomic;
pub mod cell;
pub mod char;
@@ -151,7 +152,6 @@ mod bool {
// note: does not need to be public
mod tuple;
mod array;
#[doc(hidden)]
mod core {

View File

@@ -448,7 +448,8 @@ impl<T, E> Result<T, E> {
/// ```
/// use std::old_io::IoResult;
///
/// let mut buffer = &mut b"1\n2\n3\n4\n";
/// let mut buffer: &[u8] = b"1\n2\n3\n4\n";
/// let mut buffer = &mut buffer;
///
/// let mut sum = 0;
///