kyren / gc-arena

Incremental garbage collection from safe Rust
Creative Commons Zero v1.0 Universal
436 stars 36 forks source link

Provide a few nice convenience methods on Gc #103

Closed kyren closed 3 days ago

kyren commented 4 days ago

Adds Gc::new_static and Gc::erase.

Gc::new_static allows for creating a Gc from any 'static type without bothering with a Collect impl. Uses the transparent StaticCollect wrapper internally to provide an empty Collect impl and casts the resulting pointer.

Gc::erase is simply a safe version of Gc::cast that casts to (), which we know is always safe.

As a drive-by change, also provides a for<'a> Rootable<'a> impl for StaticCollect, since it's easy to do and sometimes useful (there is an identical type in piccolo that exists only because the impl didn't exist on StaticCollect)