Struct BSTArray

Source
#[repr(C)]
pub struct BSTArray<T, A = TESGlobalAlloc>{ /* private fields */ }
Expand description

A binary-compatible, growable array.

BSTArray<T, A> is a contiguous, heap-allocated collection of elements of type T with memory layout designed to match Havok’s native BSTArray. This type is similar to Vec<T> in usage but may differ in layout due to alignment, padding, or platform-specific serialization constraints.

This array uses a custom allocator A (which implements [Allocator]) to control memory allocation. In contexts where allocation is fixed (e.g., read-only arrays or statically-sized blocks), capacity may be fixed or omitted entirely.

Internally, the array stores:

  • a pointer to the data buffer
  • the number of elements (len)
  • the capacity of the allocation (cap)

§Features

  • Compatible with Havok’s binary layout for BSTArray<T>
  • Supports growable or fixed-capacity semantics
  • Custom allocator support (A: Allocator)
  • Methods similar to Vec<T>

§Panics

Most methods panic under the following conditions:

  • Indexing out of bounds (array[index])
  • Reserving more capacity than is possible
  • Pushing to a full fixed-capacity array (if applicable)

§Example


let mut array = BSTArray::<i32>::new();
array.push(1);
array.push(2);
assert_eq!(array.len(), 2);
assert_eq!(array[1], 2);

§See also

Implementations§

Source§

impl<T, A> BSTArray<T, A>

Source

pub const fn new() -> Self

Creates a new, empty BSTArray<T, A> with the specified allocator.

The array will not allocate until elements are pushed.

§Example

let array = BSTArray::<i32>::new();
assert!(array.is_empty());
Source

pub fn with_capacity(capacity: usize) -> Self

Creates a new, empty BSTArray<T, A> with the capacity.

§Example

let array = BSTArray::<i32>::with_capacity(5);
assert_eq!(array.capacity(), 5);
Source

pub const fn len(&self) -> usize

Returns the number of elements in the array.

This is also referred to as the array’s “length”.

§Example

let array = BSTArray::<i32>::new();
assert_eq!(array.len(), 0);
Source

pub const fn is_empty(&self) -> bool

Returns true if the array contains no elements.

§Example

let array = BSTArray::<i32>::new();
assert!(array.is_empty());
Source

pub const fn capacity(&self) -> usize

Returns the total number of elements the array can hold without reallocating.

This is the allocated capacity, which may be larger than the current length.

§Example

let mut array = BSTArray::<i32>::with_capacity(10);
assert!(array.capacity() >= 10);
Source

pub fn shrink_to_fit(&mut self)

Shrinks the capacity of the array as much as possible.

It will drop any excess capacity not used by the current elements.

§Examples

let mut array = BSTArray::<i32>::with_capacity(10);
array.push(1);
assert_eq!(array.len(), 1);
array.shrink_to_fit();
assert!(array.capacity() >= array.len());
Source

pub fn push(&mut self, value: T)

Appends an element to the back of the array.

§Panics

Panics if the array is at fixed capacity and cannot grow.

§Example

let mut array = BSTArray::<i32>::new();
array.push(5);
assert_eq!(array[0], 5);
Source

pub fn pop(&mut self) -> Option<T>

Removes the last element from the array and returns it, or None if it’s empty.

§Example

let mut array = BSTArray::<i32>::new();
array.push(1);
assert_eq!(array.pop(), Some(1));
assert_eq!(array.pop(), None);
Source

pub fn get(&self, index: usize) -> Option<&T>

Returns a reference to the element at the given index, if it exists.

§Example

let mut array = BSTArray::<i32>::new();
array.push(42);
assert_eq!(array.get(0), Some(&42));
assert_eq!(array.get(1), None);
Source

pub fn get_mut(&mut self, index: usize) -> Option<&mut T>

Returns a mutable reference to the element at the given index, if it exists.

§Example

let mut array = BSTArray::<i32>::new();
array.push(10);
if let Some(x) = array.get_mut(0) {
    *x += 1;
}
assert_eq!(array[0], 11);
Source

pub fn clear(&mut self)

Clears the array, removing all elements but preserving the capacity.

§Examples

let mut array = BSTArray::<i32>::with_capacity(10);
array.push(1);
array.push(2);
assert_eq!(array.len(), 2);
array.clear();
assert_eq!(array.len(), 0);
assert_eq!(array.capacity(), 10); // Capacity is preserved
Source

pub const fn as_non_null_ptr(&mut self) -> Option<NonNull<T>>

Returns a non null pointer of the array’s buffer.

Source

pub const fn as_const_non_null_ptr(&self) -> Option<ConstNonNull<T>>

Returns a non null pointer of the array’s buffer.

Source

pub fn contains(&self, value: &T) -> bool
where T: PartialEq,

Checks if the array contains the given element.

Returns true if the element is present in the array, and false otherwise.

§Examples

let mut array = BSTArray::<i32>::with_capacity(10);
array.push(1);
array.push(2);
assert!(array.contains(&1));
assert!(!array.contains(&3));
Source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(&T) -> bool,

Retains only the elements that satisfy the predicate.

This method takes a closure that accepts an element of the array and returns a boolean. Elements for which the closure returns true will be kept, while elements for which it returns false will be removed.

§Examples

let mut array = BSTArray::<i32>::with_capacity(10);
array.push(1);
array.push(2);
array.push(3);
array.retain(|&x| x > 1);
assert_eq!(array.len(), 2);
assert!(array.contains(&2));
assert!(array.contains(&3));
§Panics

array ptr is null

Source

pub fn resize(&mut self, new_size: usize, value: T)
where T: Clone,

Resizes the array to the specified length.

If the list is shorter, it will be extended with cloning the value given as the argument.

§Examples

let mut array = BSTArray::<i32>::with_capacity(10);
array.push(1);
array.push(2);
array.resize(5, 0);
assert_eq!(array.len(), 5);
assert_eq!(array[3], 0);
Source

pub fn drain<R>(&mut self, range: R) -> BSTDrain<'_, T, A>
where R: RangeBounds<usize>,

Removes a range of elements from the array, returning them as a vector.

This method removes the elements within the specified range and returns them as a Vec<T>. The range must be within the bounds of the array.

§Examples

let mut array = BSTArray::<i32>::with_capacity(10);
array.push(1);
array.push(2);
array.push(3);
array.push(4);
array.push(5);
let drained = array.drain(0..2);
assert_eq!(drained.collect::<Vec<_>>(), vec![1, 2]);
assert_eq!(array.len(), 3);
assert_eq!(array[0], 3);
assert_eq!(array[1], 4);
assert_eq!(array[2], 5);
§Panics

Panics if the range is out of bounds.

Source

pub const fn as_slice(&self) -> &[T]

Returns a slice of all elements in the array.

Source

pub const fn as_mut_slice(&mut self) -> &mut [T]

Returns a mutable slice of all elements in the array.

Source

pub const fn iter(&self) -> BSTArrayIterator<'_, T, A>

Returns an iterator over the elements of the array.

This iterator yields references to the elements in the array.

§Examples

let mut array = BSTArray::<i32>::with_capacity(10);
array.push(1);
array.push(2);
let sum: i32 = array.iter().sum();
assert_eq!(sum, 3);

Trait Implementations§

Source§

impl<T, A> Clone for BSTArray<T, A>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T, A> Debug for BSTArray<T, A>
where T: Debug, A: SelflessAllocator,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Default for BSTArray<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T, A> Drop for BSTArray<T, A>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T, A> Extend<T> for BSTArray<T, A>

Source§

fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<T, A> Hash for BSTArray<T, A>
where T: Hash, A: SelflessAllocator,

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T, A> Index<usize> for BSTArray<T, A>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T, A> IndexMut<usize> for BSTArray<T, A>

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a, T, A> IntoIterator for &'a BSTArray<T, A>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = BSTArrayIterator<'a, T, A>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T, A> IntoIterator for &'a mut BSTArray<T, A>

Source§

type Item = &'a mut T

The type of the elements being iterated over.
Source§

type IntoIter = BSTArrayIterMut<'a, T, A>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T, A> IntoIterator for BSTArray<T, A>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = BSTArrayIntoIterator<T, A>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T, A> Ord for BSTArray<T, A>
where T: Ord, A: SelflessAllocator,

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T, A> PartialEq<&[T]> for BSTArray<T, A>

Source§

fn eq(&self, other: &&[T]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, A> PartialEq<Vec<T>> for BSTArray<T, A>

Source§

fn eq(&self, other: &Vec<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, A> PartialEq for BSTArray<T, A>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, A> PartialOrd for BSTArray<T, A>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T, A> Eq for BSTArray<T, A>
where T: Eq, A: SelflessAllocator,

Auto Trait Implementations§

§

impl<T, A> Freeze for BSTArray<T, A>

§

impl<T, A> RefUnwindSafe for BSTArray<T, A>

§

impl<T, A> Send for BSTArray<T, A>
where A: Send, T: Send,

§

impl<T, A> Sync for BSTArray<T, A>
where A: Sync, T: Sync,

§

impl<T, A> Unpin for BSTArray<T, A>
where A: Unpin, T: Unpin,

§

impl<T, A> UnwindSafe for BSTArray<T, A>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more