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>
impl<R: Region<Header>> RawDynVec<R>
Sourcepub fn with_region(region: R) -> Self
pub fn with_region(region: R) -> Self
Creates a new RawDynVec with the given region.
Sourcepub fn try_insert<T>(&mut self, item: T) -> Result<Handle<T>, T>
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.
Sourcepub fn insert<T>(&mut self, item: T) -> Handle<T>
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.
Sourcepub unsafe fn insert_raw(
&mut self,
layout: Layout,
drop_fn: Option<fn(*mut u8)>,
) -> Result<RawHandle, ()>
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_fnfunction must cause the object to be dropped. - The allocated data must get initialized before it being dropped.
Sourcepub fn remove<T>(&mut self, handle: Handle<T>) -> Result<T, ()>
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.
Sourcepub fn remove_raw(&mut self, handle: RawHandle) -> Result<(), ()>
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.
Sourcepub fn get_ptr<T>(&self, handle: Handle<T>) -> *const T
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.
Sourcepub fn get_mut_ptr<T>(&self, handle: Handle<T>) -> *mut T
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.
Sourcepub fn get_ptr_raw(&mut self, handle: RawHandle) -> *const u8
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.
Sourcepub fn get_mut_ptr_raw(&mut self, handle: RawHandle) -> *mut u8
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.
Sourcepub fn try_get<T>(&self, handle: Handle<T>) -> Option<&T>
pub fn try_get<T>(&self, handle: Handle<T>) -> Option<&T>
Tries to get a reference to the data located by the given handle.
Sourcepub fn try_get_mut<T>(&mut self, handle: Handle<T>) -> Option<&mut T>
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§impl RawDynVec<Chunks<Header>>
impl RawDynVec<Chunks<Header>>
Sourcepub fn with_chunk_size(min_chunk_size: usize) -> Self
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.
Sourcepub fn with_chunks(min_chunk_size: usize, chunk_count: usize) -> Self
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.