RawDynVec

Struct RawDynVec 

Source
pub struct RawDynVec<R: Region<Header>> { /* private fields */ }
Expand description

A dynamic vector, able to store any kind of data.

Implementations§

Source§

impl<R: Region<Header>> RawDynVec<R>

Source

pub fn with_region(region: R) -> Self

Creates a new RawDynVec with the given region.

Source

pub fn count(&self) -> usize

Returns the number of items this vector stores.

Source

pub fn try_insert<T>(&mut self, item: T) -> Result<Handle<T>, T>

Tries to insert a T into the vector and returns a Handle to this T. If the T cannot be allocated, it gets returned as the error.

Source

pub fn clear(&mut self)

Clears the whole vector, leaving it empty.

Source

pub fn insert<T>(&mut self, item: T) -> Handle<T>

Inserts a T into the vector and returns a Handle to this T.

§Panics

This function panics if the T could not be allocated.

Source

pub unsafe fn insert_raw( &mut self, layout: Layout, drop_fn: Option<fn(*mut u8)>, ) -> Result<RawHandle, ()>

Allocates memory as described by the given layout. If the allocation is a success, a raw handle to the allocation is returned. In this case, it is up to the caller to initialize the allocated value because the vector now assumes it is initialized.

§Safety
  • The drop_fn function must cause the object to be dropped.
  • The allocated data must get initialized before it being dropped.
Source

pub fn remove<T>(&mut self, handle: Handle<T>) -> Result<T, ()>

Tries to remove the T located by the given handle. If the handle was invalid, Err(()) is returned.

Source

pub fn remove_raw(&mut self, handle: RawHandle) -> Result<(), ()>

Tries to remove an item out of the vector. If the handle was invalid Err(()) is returned.

As the handle is raw, the item cannot be returned. But it is still dropped properly.

Source

pub fn get_ptr<T>(&self, handle: Handle<T>) -> *const T

Gets a pointer to the data located by the given handle.

§Safety

If the null pointer is returned, the handle was invalid.

Source

pub fn get_mut_ptr<T>(&self, handle: Handle<T>) -> *mut T

Gets a pointer to the data located by the given handle.

§Safety

If the null pointer is returned, the handle was invalid.

Source

pub fn get_ptr_raw(&mut self, handle: RawHandle) -> *const u8

Gets a pointer to the data located by the given handle.

§Safety

If the null pointer is returned, the handle was invalid.

Source

pub fn get_mut_ptr_raw(&mut self, handle: RawHandle) -> *mut u8

Gets a pointer to the data located by the given handle.

§Safety

If the null pointer is returned, the handle was invalid.

Source

pub fn try_get<T>(&self, handle: Handle<T>) -> Option<&T>

Tries to get a reference to the data located by the given handle.

Source

pub fn try_get_mut<T>(&mut self, handle: Handle<T>) -> Option<&mut T>

Tries to get a reference to the data located by the given handle.

Source

pub fn get<T>(&self, handle: Handle<T>) -> &T

Gets a reference to the data located by the given handle.

§Panics

If the handle is valid, this function panics.

Source

pub fn get_mut<T>(&mut self, handle: Handle<T>) -> &mut T

Gets a reference to the data located by the given handle.

§Panics

If the handle is valid, this function panics.

Source§

impl RawDynVec<Chunks<Header>>

Source

pub fn new() -> Self

Allocates a new DynVec with a minimal chunk size of 1024 bytes.

Source

pub fn with_chunk_size(min_chunk_size: usize) -> Self

Creates a new DynVec with the given chunk size. Note that chunks can be allocated with a larger size if large objects need to be inserted.

Source

pub fn with_chunks(min_chunk_size: usize, chunk_count: usize) -> Self

Creates a new DynVec with the given chunk size and chunk count. This function allocates chunk_count chunks in advance.

Trait Implementations§

Source§

impl<R: Default + Region<Header>> Default for RawDynVec<R>

Source§

fn default() -> RawDynVec<R>

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

impl<R: Region<Header>> Drop for RawDynVec<R>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<R: Region<Header>, T> Index<Handle<T>> for RawDynVec<R>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, index: Handle<T>) -> &Self::Output

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

impl<R: Region<Header>, T> IndexMut<Handle<T>> for RawDynVec<R>

Source§

fn index_mut(&mut self, index: Handle<T>) -> &mut Self::Output

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

Auto Trait Implementations§

§

impl<R> Freeze for RawDynVec<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for RawDynVec<R>
where R: RefUnwindSafe,

§

impl<R> Send for RawDynVec<R>
where R: Send,

§

impl<R> Sync for RawDynVec<R>
where R: Sync,

§

impl<R> Unpin for RawDynVec<R>
where R: Unpin,

§

impl<R> UnwindSafe for RawDynVec<R>
where R: UnwindSafe,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.