pub trait Allocator {
type Alloc;
Show 21 methods
// Required methods
fn as_raw_allocator(&mut self) -> &mut Self::Alloc;
fn yield_point(&mut self);
fn request_gc(&mut self, request: CollectionType);
// Provided methods
fn alloc<T>(&mut self, val: T) -> Gc<T, Self::Alloc>
where Self::Alloc: Alloc<T> { ... }
fn alloc_mut<T>(&mut self, val: T) -> GcMut<T, Self::Alloc>
where Self::Alloc: AllocMut<T>,
<Self::Alloc as Alloc<T>>::MutTy: From<T> { ... }
fn try_alloc<T>(&mut self, val: T) -> Result<Gc<T, Self::Alloc>, Error>
where Self::Alloc: Alloc<T> { ... }
fn alloc_with<F, T>(&mut self, f: F) -> Gc<T, Self::Alloc>
where F: FnOnce() -> T,
Self::Alloc: Alloc<T> { ... }
fn try_gc_alloc_with<F, T>(
&mut self,
retry_limit: Option<u32>,
f: F,
) -> Result<Gc<T, Self::Alloc>, Error>
where F: FnOnce() -> T,
Self::Alloc: Alloc<T> { ... }
unsafe fn try_gc_alloc_init<F, T>(
&mut self,
retry_limit: Option<u32>,
layout: Layout,
init: F,
) -> Result<Gc<T, Self::Alloc>, Error>
where T: ?Sized,
F: FnOnce(NonNull<u8>),
Self::Alloc: Alloc<T> { ... }
fn try_gc_alloc_setup<F, T>(
&mut self,
retry_limit: Option<u32>,
init: F,
) -> Result<Gc<T, Self::Alloc>, Error>
where T: ?Sized + Default,
F: FnOnce(&mut T),
Self::Alloc: Alloc<T> { ... }
fn try_alloc_with<F, T>(
&mut self,
f: F,
) -> Result<Gc<T, Self::Alloc>, Error>
where F: FnOnce() -> T,
Self::Alloc: Alloc<T> { ... }
fn alloc_slice_copy<T>(&mut self, src: &[T]) -> Gc<[T], Self::Alloc>
where T: Copy,
Self::Alloc: Alloc<[T]> { ... }
fn alloc_slice_clone<T>(&mut self, src: &[T]) -> Gc<[T], Self::Alloc>
where T: Clone,
Self::Alloc: Alloc<[T]> { ... }
fn alloc_str(&mut self, src: &str) -> Gc<str, Self::Alloc>
where Self::Alloc: Alloc<str> { ... }
fn alloc_slice_fill_with<T, F>(
&mut self,
len: usize,
f: F,
) -> Gc<[T], Self::Alloc>
where F: FnMut(usize) -> T,
Self::Alloc: Alloc<[T]> { ... }
fn try_alloc_slice_fill_with<T, F>(
&mut self,
len: usize,
f: F,
) -> Result<Gc<[T], Self::Alloc>, Error>
where F: FnMut(usize) -> T,
Self::Alloc: Alloc<[T]> { ... }
fn try_gc_alloc_slice_fill_with<T, F>(
&mut self,
retry_limit: Option<u32>,
len: usize,
f: F,
) -> Result<Gc<[T], Self::Alloc>, Error>
where F: FnMut(usize) -> T,
Self::Alloc: Alloc<[T]> { ... }
fn alloc_slice_fill_copy<T>(
&mut self,
len: usize,
value: T,
) -> Gc<[T], Self::Alloc>
where T: Copy,
Self::Alloc: Alloc<[T]> { ... }
fn alloc_slice_fill_clone<T>(
&mut self,
len: usize,
value: &T,
) -> Gc<[T], Self::Alloc>
where T: Clone,
Self::Alloc: Alloc<[T]> { ... }
fn alloc_slice_fill_iter<T, I>(&mut self, iter: I) -> Gc<[T], Self::Alloc>
where I: IntoIterator<Item = T>,
I::IntoIter: ExactSizeIterator,
Self::Alloc: Alloc<[T]> { ... }
fn alloc_slice_fill_default<T>(
&mut self,
len: usize,
) -> Gc<[T], Self::Alloc>
where T: Default,
Self::Alloc: Alloc<[T]> { ... }
}
Expand description
Notes:
- Encode metadata in Gc pointer
- Swap error out with trait system?
Required Associated Types§
Required Methods§
fn as_raw_allocator(&mut self) -> &mut Self::Alloc
Sourcefn yield_point(&mut self)
fn yield_point(&mut self)
Mark a location where this allocator can safely yield to garbage collection. Garbage connection will only occur when the required allocators have yielded. Calling this function does not guarantee garbage collection will occur.
For garbage collectors that do not require yield points, this will be treated as a no-op.
Sourcefn request_gc(&mut self, request: CollectionType)
fn request_gc(&mut self, request: CollectionType)
Request that garbage collection is performed at the next yield_point
. This function should
only be called if recommended by the underlying implementation. Extraneous calls to this
function may have an adverse effect on performance.
Calling this function gives a GC a strong suggestion that garbage collection should be performed at the next opportunity. However, this does not guarantee that garbage collection can or will be performed.
Provided Methods§
fn alloc<T>(&mut self, val: T) -> Gc<T, Self::Alloc>
fn alloc_mut<T>(&mut self, val: T) -> GcMut<T, Self::Alloc>
fn try_alloc<T>(&mut self, val: T) -> Result<Gc<T, Self::Alloc>, Error>
fn alloc_with<F, T>(&mut self, f: F) -> Gc<T, Self::Alloc>
fn try_gc_alloc_with<F, T>( &mut self, retry_limit: Option<u32>, f: F, ) -> Result<Gc<T, Self::Alloc>, Error>
Sourceunsafe fn try_gc_alloc_init<F, T>(
&mut self,
retry_limit: Option<u32>,
layout: Layout,
init: F,
) -> Result<Gc<T, Self::Alloc>, Error>
unsafe fn try_gc_alloc_init<F, T>( &mut self, retry_limit: Option<u32>, layout: Layout, init: F, ) -> Result<Gc<T, Self::Alloc>, Error>
This function attempts to allocate a new object on the heap in accordance to the given layout. The caller can then choose how they would like to initialize that memory.
§Safety
The caller must fully initialize the object data via the init function. Failing to do so may
result in undefined behavior comparable to calling std::mem::MaybeUninit::assume_init
without fully initializing the type.
Sourcefn try_gc_alloc_setup<F, T>(
&mut self,
retry_limit: Option<u32>,
init: F,
) -> Result<Gc<T, Self::Alloc>, Error>
fn try_gc_alloc_setup<F, T>( &mut self, retry_limit: Option<u32>, init: F, ) -> Result<Gc<T, Self::Alloc>, Error>
This function is intended to be a safe equivalent for [try_gc_alloc_init
]. To avoid any
unsafe code the unitialized value is first initialized to its default value before being
handed to the user.
fn try_alloc_with<F, T>(&mut self, f: F) -> Result<Gc<T, Self::Alloc>, Error>
fn alloc_slice_copy<T>(&mut self, src: &[T]) -> Gc<[T], Self::Alloc>
fn alloc_slice_clone<T>(&mut self, src: &[T]) -> Gc<[T], Self::Alloc>
fn alloc_str(&mut self, src: &str) -> Gc<str, Self::Alloc>
fn alloc_slice_fill_with<T, F>( &mut self, len: usize, f: F, ) -> Gc<[T], Self::Alloc>
fn try_alloc_slice_fill_with<T, F>( &mut self, len: usize, f: F, ) -> Result<Gc<[T], Self::Alloc>, Error>
fn try_gc_alloc_slice_fill_with<T, F>( &mut self, retry_limit: Option<u32>, len: usize, f: F, ) -> Result<Gc<[T], Self::Alloc>, Error>
fn alloc_slice_fill_copy<T>( &mut self, len: usize, value: T, ) -> Gc<[T], Self::Alloc>
fn alloc_slice_fill_clone<T>( &mut self, len: usize, value: &T, ) -> Gc<[T], Self::Alloc>
fn alloc_slice_fill_iter<T, I>(&mut self, iter: I) -> Gc<[T], Self::Alloc>
fn alloc_slice_fill_default<T>(&mut self, len: usize) -> Gc<[T], Self::Alloc>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.