Trait for fixed size arrays.
| 4 | |
| 5 | /// Trait for fixed size arrays. |
| 6 | pub unsafe trait Array { |
| 7 | /// The array’s element type |
| 8 | type Item; |
| 9 | |
| 10 | #[doc(hidden)] |
| 11 | /// The smallest index type that indexes the array. |
| 12 | type Index: Index; |
| 13 | |
| 14 | /// Returns a raw pointer to the slice's buffer. |
| 15 | fn as_ptr(&self) -> *const Self::Item; |
| 16 | |
| 17 | /// Returns an unsafe mutable pointer to the slice's buffer. |
| 18 | fn as_mut_ptr(&mut self) -> *mut Self::Item; |
| 19 | |
| 20 | /// Returns number of element the array can hold |
| 21 | fn capacity() -> usize; |
| 22 | |
| 23 | /// Converts the array to immutable slice |
| 24 | #[inline(always)] |
| 25 | fn as_slice(&self) -> &[Self::Item] { |
| 26 | let ptr = self as *const _ as *const _; |
| 27 | unsafe { slice::from_raw_parts(ptr, Self::capacity()) } |
| 28 | } |
| 29 | |
| 30 | /// Converts the array to mutable slice |
| 31 | #[inline(always)] |
| 32 | fn as_mut_slice(&mut self) -> &mut [Self::Item] { |
| 33 | let ptr = self as *mut _ as *mut _; |
| 34 | unsafe { slice::from_raw_parts_mut(ptr, Self::capacity()) } |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | #[doc(hidden)] |
| 39 | pub trait Index: PartialEq + Copy { |
nothing calls this directly
no outgoing calls
no test coverage detected