Skip to content

Commit 2e62581

Browse files
committed
use cast for ArrayProxy
1 parent c339d85 commit 2e62581

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/generate/array_proxy.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,20 @@ pub struct ArrayProxy<T, const COUNT: usize, const STRIDE: usize> {
1616
#[allow(clippy::len_without_is_empty)]
1717
impl<T, const C: usize, const S: usize> ArrayProxy<T, C, S> {
1818
/// Get a reference from an [ArrayProxy] with no bounds checking.
19-
pub unsafe fn get_ref(&self, index: usize) -> &T {
20-
let base = self as *const Self as usize;
21-
let address = base + S * index;
22-
&*(address as *const T)
19+
pub const unsafe fn get_ref(&self, index: usize) -> &T {
20+
&*(self as *const Self).cast::<u8>().add(S * index).cast::<T>()
2321
}
2422
/// Get a reference from an [ArrayProxy], or return `None` if the index
2523
/// is out of bounds.
26-
pub fn get(&self, index: usize) -> Option<&T> {
24+
pub const fn get(&self, index: usize) -> Option<&T> {
2725
if index < C {
2826
Some(unsafe { self.get_ref(index) })
2927
} else {
3028
None
3129
}
3230
}
3331
/// Return the number of items.
34-
pub fn len(&self) -> usize {
32+
pub const fn len(&self) -> usize {
3533
C
3634
}
3735
}

0 commit comments

Comments
 (0)