Move Array trait to separate file

Also remove the ::new() method on the trait
This commit is contained in:
root
2015-05-22 13:26:01 +02:00
parent 00466e6efd
commit 1b42f992ed
2 changed files with 48 additions and 42 deletions
+39
View File
@@ -0,0 +1,39 @@
/// Trait for fixed size arrays.
pub unsafe trait Array {
/// The array's element type
type Item;
#[doc(hidden)]
fn as_ptr(&self) -> *const Self::Item;
#[doc(hidden)]
fn as_mut_ptr(&mut self) -> *mut Self::Item;
#[doc(hidden)]
fn capacity() -> usize;
}
macro_rules! fix_array_impl {
($len:expr ) => (
unsafe impl<T> Array for [T; $len] {
type Item = T;
#[inline(always)]
fn as_ptr(&self) -> *const T { self as *const _ as *const _ }
#[inline(always)]
fn as_mut_ptr(&mut self) -> *mut T { self as *mut _ as *mut _}
#[inline(always)]
fn capacity() -> usize { $len }
}
)
}
macro_rules! fix_array_impl_recursive {
() => ();
($len:expr, $($more:expr,)*) => (
fix_array_impl!($len);
fix_array_impl_recursive!($($more,)*);
);
}
fix_array_impl_recursive!(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, 40, 48, 56, 64, 72, 96, 128, 160, 192, 224,);