Updates for making soa no_std

This commit is contained in:
Richard Feldman 2024-10-12 21:27:41 -04:00
parent 178bc469e6
commit 44d00e1f13
No known key found for this signature in database
GPG key ID: DAC334802F365236
21 changed files with 164 additions and 151 deletions

View file

@ -14,8 +14,8 @@ use crate::soa_slice::Slice;
/// Unlike a Rust pointer, this is a u32 offset
/// rather than usize.
pub struct Index<T> {
pub(crate) index: u32,
pub(crate) _marker: PhantomData<T>,
pub index: u32,
pub _marker: PhantomData<T>,
}
impl<T> PartialEq for Index<T> {
@ -81,7 +81,7 @@ impl<T> Index<T> {
}
}
impl<'a, T> core::ops::Index<Index<T>> for [T] {
impl<T> core::ops::Index<Index<T>> for [T] {
type Output = T;
fn index(&self, index: Index<T>) -> &Self::Output {
@ -89,7 +89,7 @@ impl<'a, T> core::ops::Index<Index<T>> for [T] {
}
}
impl<'a, T> core::ops::IndexMut<Index<T>> for [T] {
impl<T> core::ops::IndexMut<Index<T>> for [T] {
fn index_mut(&mut self, index: Index<T>) -> &mut Self::Output {
&mut self[index.index()]
}

View file

@ -9,9 +9,9 @@ use crate::soa_index::Index;
/// rather than a pointer, and the length is u16.
#[derive(PartialEq, Eq, PartialOrd, Ord)]
pub struct Slice<T> {
pub(crate) start: u32,
pub(crate) length: u16,
pub(crate) _marker: core::marker::PhantomData<T>,
pub start: u32,
pub length: u16,
pub _marker: core::marker::PhantomData<T>,
}
impl<T> fmt::Debug for Slice<T> {
@ -51,22 +51,10 @@ impl<T> Slice<T> {
}
}
/// Create an empty slice that isn't associated with any particular array.
/// This is marked as unsafe because it omits the runtime checks (in debug builds)
/// which verify that indices made from this slice are compared with other
/// indices into the original array.
pub unsafe fn empty_unchecked() -> Self {
Self {
start: 0,
length: 0,
_marker: PhantomData,
}
}
/// This is unsafe because it doesn't verify that the start index being returned is being used with the original
/// slice it was created with. Self::get_in is the safe alternative to this.
pub const fn start(self) -> usize {
self.start as usize
pub const fn start(self) -> u32 {
self.start
}
pub fn advance(&mut self, amount: u32) {
@ -115,18 +103,6 @@ impl<T> Slice<T> {
_marker: PhantomData,
}
}
/// Create a new slice that isn't associated with any particular array.
/// This is marked as unsafe because it omits the runtime checks (in debug builds)
/// which verify in debug builds that indices made from this slice are compared with other
/// indices into the original array.
pub const unsafe fn new_unchecked(start: u32, length: u16) -> Self {
Self {
start,
length,
_marker: PhantomData,
}
}
}
impl<T> IntoIterator for Slice<T> {