Struct hkArray

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

A dynamic array container C++’s hkArray, backed by a custom allocator.

§Example

use commonlibsse_ng::re::hkArray::hkArray;

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

Note: The default allocator (SkyrimAllocator) only works in-game. For examples outside of the game, use RustAllocator.

Implementations§

Source§

impl<T, A> hkArray<T, A>

Source

pub const fn new() -> Self

Creates a new empty array.

§Example
use commonlibsse_ng::re::hkArray::hkArray;

let array: hkArray<u32> = hkArray::new();
assert!(array.is_empty());
Source

pub fn with_capacity(capacity: i32) -> Self

Source

pub const fn len(&self) -> usize

Returns the number of elements in the array.

§Example
use commonlibsse_ng::re::hkArray::hkArray;

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

pub const fn capacity(&self) -> i32

Returns the capacity of the array.

§Example
use commonlibsse_ng::re::hkArray::hkArray;

let array = hkArray::<u32>::new();
assert_eq!(array.capacity(), 0);
Source

pub const fn is_empty(&self) -> bool

Checks if the array is empty.

§Example
use commonlibsse_ng::re::hkArray::hkArray;

let array = hkArray::<u32>::new();
assert!(array.is_empty());
Source

pub fn reserve(&mut self, new_capacity: i32)

Reserves capacity for at least new_capacity elements.

§Panics

Panics if new_capacity exceeds the internal capacity limit.

§Example
use commonlibsse_ng::re::hkArray::hkArray;

let mut array = hkArray::<u32>::new();
array.reserve(10);
assert!(array.capacity() >= 10);
Source

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

Pushes a new element to the end of the array.

§Panics

Panics if memory allocation fails.

§Example
use commonlibsse_ng::re::hkArray::hkArray;

let mut array = hkArray::<u32>::new();
array.push(42);
Source

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

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

§Example
use commonlibsse_ng::re::hkArray::hkArray;

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

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

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

§Example
use commonlibsse_ng::re::hkArray::hkArray;

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

pub const 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
use commonlibsse_ng::re::hkArray::hkArray;

let mut array = hkArray::<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
use commonlibsse_ng::re::BSTArray::{BSTArray};

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 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
use commonlibsse_ng::re::hkArray::hkArray;

let mut array = hkArray::<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
use commonlibsse_ng::re::hkArray::hkArray;

let mut array = hkArray::<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));
Source

pub fn drain<R>(&mut self, range: R) -> hkArrayDrain<'_, 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
use commonlibsse_ng::re::hkArray::hkArray;

let mut array = hkArray::<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 iter(&self) -> hkArrayRefIterator<'_, T, A>

Return iterator

Source

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

Return readonly slice.

Source

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

Return mutable slice.

Source§

impl<T, A> hkArray<T, A>
where T: Clone, A: SelflessAllocator,

Source

pub fn resize(&mut self, count: i32, value: T)

Resizes the array to the specified length, filling new elements with the given value.

§Panics

Panics if count is negative or exceeds the maximum allowed capacity.

§Example
use commonlibsse_ng::re::hkArray::hkArray;

let mut array = hkArray::<u32>::new();
array.resize(3, 7);
assert_eq!(array.len(), 3);
assert_eq!(array[0], 7);

Trait Implementations§

Source§

impl<T: Clone, A: Clone + SelflessAllocator> Clone for hkArray<T, A>

Source§

fn clone(&self) -> hkArray<T, A>

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: Debug, A: Debug + SelflessAllocator> Debug for hkArray<T, A>

Source§

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

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

impl<T, A> Default for hkArray<T, A>

Source§

fn default() -> Self

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

impl<T: Hash, A: Hash + SelflessAllocator> Hash for hkArray<T, A>

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 hkArray<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 hkArray<T, A>

Source§

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

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

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

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = hkArrayIterator<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: Ord, A: Ord + SelflessAllocator> Ord for hkArray<T, A>

Source§

fn cmp(&self, other: &hkArray<T, A>) -> 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: PartialEq, A: PartialEq + SelflessAllocator> PartialEq for hkArray<T, A>

Source§

fn eq(&self, other: &hkArray<T, A>) -> 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: PartialOrd, A: PartialOrd + SelflessAllocator> PartialOrd for hkArray<T, A>

Source§

fn partial_cmp(&self, other: &hkArray<T, A>) -> 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: Eq, A: Eq + SelflessAllocator> Eq for hkArray<T, A>

Source§

impl<T, A: SelflessAllocator> StructuralPartialEq for hkArray<T, A>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T, A> UnwindSafe for hkArray<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