about summary refs log tree commit diff
path: root/src/libcore/array.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-03-18 08:27:22 +0000
committerbors <bors@rust-lang.org>2015-03-18 08:27:22 +0000
commit46f649c479ce40f3b4590590dda6c2895e8d60f6 (patch)
tree1c775c64a8d726183113d966c2b01ae6d60c6289 /src/libcore/array.rs
parentf9a7bc58f89b9b15eb1269f0c0d68baf5fc7e966 (diff)
parentdccd17d23e6e67e410e41f97ba9feb7f71717627 (diff)
downloadrust-46f649c479ce40f3b4590590dda6c2895e8d60f6.tar.gz
rust-46f649c479ce40f3b4590590dda6c2895e8d60f6.zip
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]
Diffstat (limited to 'src/libcore/array.rs')
-rw-r--r--src/libcore/array.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/libcore/array.rs b/src/libcore/array.rs
index 0d98cff7e6a..edb11df5489 100644
--- a/src/libcore/array.rs
+++ b/src/libcore/array.rs
@@ -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] {