MCPcopy Create free account
hub / github.com/aiscriptdev/aiscript / Collect

Interface Collect

aiscript-arena/src/collect.rs:23–40  ·  view source on GitHub ↗

A trait for garbage collected objects that can be placed into `Gc` pointers. This trait is unsafe, because `Gc` pointers inside an Arena are assumed never to be dangling, and in order to ensure this certain rules must be followed: 1. `Collect::trace` *must* trace over *every* `Gc` pointer held inside this type, and cannot fail. 2. Held `Gc` pointers must not be accessed inside `Drop::drop` since

Source from the content-addressed store, hash-verified

21/// while ensuring that the write barrier is always executed.
22/// # Safety
23pub unsafe trait Collect {
24 /// As an optimization, if this type can never hold a `Gc` pointer and `trace` is unnecessary
25 /// to call, you may implement this method and return false. The default implementation returns
26 /// true, signaling that `Collect::trace` must be called.
27 #[inline]
28 fn needs_trace() -> bool
29 where
30 Self: Sized,
31 {
32 true
33 }
34
35 /// *Must* call `Collect::trace` on all held `Gc` pointers. If this type holds inner types that
36 /// implement `Collect`, a valid implementation would simply call `Collect::trace` on all the
37 /// held values to ensure this.
38 #[inline]
39 fn trace(&self, _cc: &Collection) {}
40}

Callers

nothing calls this directly

Implementers 11

lock.rsaiscript-arena/src/lock.rs
gc_weak.rsaiscript-arena/src/gc_weak.rs
dynamic_roots.rsaiscript-arena/src/dynamic_roots.rs
allocator_api.rsaiscript-arena/src/allocator_api.rs
gc.rsaiscript-arena/src/gc.rs
static_collect.rsaiscript-arena/src/static_collect.rs
hashbrown.rsaiscript-arena/src/hashbrown.rs
collect_impl.rsaiscript-arena/src/collect_impl.rs
lib.rsaiscript-vm/src/lib.rs
interned.rsaiscript-vm/src/string/interned.rs
state.rsaiscript-vm/src/vm/state.rs

Calls

no outgoing calls

Tested by

no test coverage detected