MCPcopy Create free account
hub / github.com/andylokandy/arraydeque / Array

Interface Array

src/array.rs:6–36  ·  view source on GitHub ↗

Trait for fixed size arrays.

Source from the content-addressed store, hash-verified

4
5/// Trait for fixed size arrays.
6pub 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)]
39pub trait Index: PartialEq + Copy {

Callers

nothing calls this directly

Implementers 1

array.rssrc/array.rs

Calls

no outgoing calls

Tested by

no test coverage detected