pub unsafe trait IGcVec<'gc, T: GcSafe<'gc, Self::Id>>: Sized + Extend<T> {
type Id: CollectorId;
Show 21 methods
fn with_capacity_in(
capacity: usize,
ctx: &'gc <Self::Id as CollectorId>::Context
) -> Self;
fn len(&self) -> usize;
unsafe fn set_len(&mut self, len: usize);
fn capacity(&self) -> usize;
fn reserve_in_place(
&mut self,
additional: usize
) -> Result<(), ReallocFailedError>;
unsafe fn as_ptr(&self) -> *const T;
fn context(&self) -> &'gc <Self::Id as CollectorId>::Context;
fn from_vec(
src: Vec<T>,
ctx: &'gc <Self::Id as CollectorId>::Context
) -> Self { ... }
fn copy_from_slice(
src: &[T],
ctx: &'gc <Self::Id as CollectorId>::Context
) -> Self
where
T: Copy,
{ ... }
fn new_in(ctx: &'gc <Self::Id as CollectorId>::Context) -> Self { ... }
fn is_empty(&self) -> bool { ... }
fn reserve(&mut self, additional: usize) { ... }
fn push(&mut self, val: T) { ... }
fn pop(&mut self) -> Option<T> { ... }
fn swap_remove(&mut self, index: usize) -> T { ... }
fn extend_from_slice(&mut self, src: &[T])
where
T: Copy,
{ ... }
fn get(&self, idx: usize) -> Option<T>
where
T: Copy,
{ ... }
fn set(&mut self, index: usize, val: T) { ... }
fn replace(&mut self, index: usize, val: T) -> T { ... }
unsafe fn as_mut_ptr(&mut self) -> *mut T { ... }
unsafe fn as_slice_unchecked(&self) -> &[T]ⓘNotable traits for &'_ mut [u8]impl Write for &'_ mut [u8]impl Read for &'_ [u8]
{ ... }
}
Expand description
Basic methods shared across all garbage collected vectors.
All garbage collectors are implicitly associated with their owning GcContext.
This can be changed by calling detatch
,
although this is currently unimplemented.
Safety
Undefined behavior if the methods violate their contracts.
All of the methods in this trait can be trusted to be implemented correctly.
Associated Types
type Id: CollectorId
type Id: CollectorId
The id of the collector
Required methods
fn with_capacity_in(
capacity: usize,
ctx: &'gc <Self::Id as CollectorId>::Context
) -> Self
fn with_capacity_in(
capacity: usize,
ctx: &'gc <Self::Id as CollectorId>::Context
) -> Self
Allocate a new vector with the specified capacity, using the specified context.
The length of the vector.
This is the number of elements that are actually
initialized, as opposed to capacity
, which is the number
of elements that are available in total.
Set the length of the vector.
Safety
All the same restrictions apply as Vec::set_len.
By the time of the next garbage collection, The underlying memory must be initialized up to the specified length, otherwise the vector’s memory will be traced incorrectly.
Undefined behavior if length is greater than capacity.
The total amount of space that is available without needing reallocation.
fn reserve_in_place(
&mut self,
additional: usize
) -> Result<(), ReallocFailedError>
fn reserve_in_place(
&mut self,
additional: usize
) -> Result<(), ReallocFailedError>
Attempt to reallocate the vector in-place, without moving the underlying pointer.
Get a pointer to this vector’s underling data.
This is unsafe for the same
Safety
Undefined behavior if the pointer is used are used after the length changes.
Provided methods
Copy the specified elements into a new vector, allocating it in the specified context
This consumes ownership of the original vector.
fn copy_from_slice(
src: &[T],
ctx: &'gc <Self::Id as CollectorId>::Context
) -> Self where
T: Copy,
fn copy_from_slice(
src: &[T],
ctx: &'gc <Self::Id as CollectorId>::Context
) -> Self where
T: Copy,
Copy the specified elements into a new vector, allocating it in the specified context
fn new_in(ctx: &'gc <Self::Id as CollectorId>::Context) -> Self
fn new_in(ctx: &'gc <Self::Id as CollectorId>::Context) -> Self
Allocate a new vector inside the specified context
Reserves capacity for at least additional
.
If this type is a GcVecCell and there are outstanding borrows references,
then this will panic as if calling RefCell::borrow_mut
.
Safety
This method is safe.
If this method finishes without panicking,
it can be assumed that new_capacity - old_capcity >= additional
Push the specified element onto the end of this vector.
If this type is a GcVecCell and there are outstanding borrows references,
then this will panic as if calling RefCell::borrow_mut
.
Safety
This method is safe.
Pop an element of the end of the vector,
returning None
if empty.
This is analogous to Vec::pop
If this type is a GcVecCell and there are outstanding borrowed references,
this will panic as if calling RefCell::borrow_mut
.
Safety
This method is safe.
fn swap_remove(&mut self, index: usize) -> T
fn swap_remove(&mut self, index: usize) -> T
Removes an element from the vector and returns it.
The removed element is replaced by the last element in the vector.
This doesn’t preserve ordering, but it is O(1)
fn extend_from_slice(&mut self, src: &[T]) where
T: Copy,
fn extend_from_slice(&mut self, src: &[T]) where
T: Copy,
Extend the vector with elements copied from the specified slice
Get the item at the specified index,
or None
if it is out of bounds.
This returns a copy of the value.
As such it requires T: Copy
Set the item at the specified index
Panics if the index is out of bounds.
Replace the item at the specified index, returning the old value.
For a traditional Vec
,
the equivalent would be mem::replace(&mut v[index], new_value)
.
unsafe fn as_mut_ptr(&mut self) -> *mut T
unsafe fn as_mut_ptr(&mut self) -> *mut T
Get a mutable pointer to the vector’s underlying data.
This is unsafe for the same reason IGcVec::as_ptr and
Safety
Undefined behavior if the pointer is used after the length changes.
Undefined behavior if the elements are mutated while there are multiple outstanding references.
Get a slice of this vector’s elements.
Safety
If this type has shared references (multiple owners), then it is undefined behavior to mutate the length while the slice is still borrowed.
In other words, the following is invalid:
let mut v = GcVecCell::<i32, EpsilonCollectorId>::new_in(context);
v.push(23);
let mut copy = v;
let slice = unsafe { v.as_slice_unchecked() };
copy.push(15);
slice[0]; // UB