From 2e62581f2edec466308df6e7447dd8ebb4243680 Mon Sep 17 00:00:00 2001 From: Andrey Zgarbul Date: Wed, 18 Oct 2023 10:35:46 +0300 Subject: [PATCH] use cast for ArrayProxy --- src/generate/array_proxy.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/generate/array_proxy.rs b/src/generate/array_proxy.rs index b47074ba..00f7064a 100644 --- a/src/generate/array_proxy.rs +++ b/src/generate/array_proxy.rs @@ -16,14 +16,12 @@ pub struct ArrayProxy { #[allow(clippy::len_without_is_empty)] impl ArrayProxy { /// Get a reference from an [ArrayProxy] with no bounds checking. - pub unsafe fn get_ref(&self, index: usize) -> &T { - let base = self as *const Self as usize; - let address = base + S * index; - &*(address as *const T) + pub const unsafe fn get_ref(&self, index: usize) -> &T { + &*(self as *const Self).cast::().add(S * index).cast::() } /// Get a reference from an [ArrayProxy], or return `None` if the index /// is out of bounds. - pub fn get(&self, index: usize) -> Option<&T> { + pub const fn get(&self, index: usize) -> Option<&T> { if index < C { Some(unsafe { self.get_ref(index) }) } else { @@ -31,7 +29,7 @@ impl ArrayProxy { } } /// Return the number of items. - pub fn len(&self) -> usize { + pub const fn len(&self) -> usize { C } }