rust_extra/arrays/
Array.rs

1// This file is part of rust-extra. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/rust-extra/master/COPYRIGHT. No part of rust-extra, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2// Copyright © 2016 The developers of rust-extra. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/rust-extra/master/COPYRIGHT.
3
4
5pub trait Array<T>
6{
7	const Size: usize;
8	const Mask: usize;
9	
10	#[inline(always)]
11	fn mask() -> usize
12	{
13		Self::Mask
14	}
15	
16	#[inline(always)]
17	unsafe fn get_unchecked(&self, index: usize) -> &T;
18	
19	#[inline(always)]
20	unsafe fn get_unchecked_mut(&mut self, index: usize) -> &mut T;
21	
22	#[inline(always)]
23	fn as_ptr(&self) -> *const T;
24	
25	#[inline(always)]
26	fn as_mut_ptr(&mut self) -> *mut T;
27	
28	#[inline(always)]
29	fn as_ptr_at(&self, index: usize) -> *const T
30	{
31		unsafe { self.as_ptr().offset(index as isize) }
32	}
33	
34	#[inline(always)]
35	fn as_mut_ptr_at(&mut self, index: usize) -> *mut T
36	{
37		unsafe { self.as_mut_ptr().offset(index as isize) }
38	}
39}