Crates.io | pgc-derive |
lib.rs | pgc-derive |
version | 0.1.1 |
source | src |
created_at | 2019-09-26 14:38:16.463802 |
updated_at | 2019-09-26 14:39:21.92612 |
description | Garbage collector derive plugin for pgc |
homepage | |
repository | |
max_upload_size | |
id | 167853 |
size | 2,487 |
Precise tracing garbage collector built in Rust featuring parallel marking and mark&sweep algorithm.
To include in your project, add the following to your Cargo.toml:
[dependencies]
pgc = "*"
This can be used pretty much like Rc, with the exception of interior mutability.
Types placed inside a Gc
and Rooted
must implement GcObject
and Send
.
use pgc::*;
struct Foo {
x: Gc<i32>,
y: i32
}
unsafe impl GcObject for Foo {
fn references(&self) -> Vec<Gc<dyn GcObject>> {
let mut v: Vec<Gc<dyn GcObject>> = vec![];
v.push(self.x);
v
}
}
To use Gc
simply call Gc::new
:
let foo = Gc::new(Foo {...});
GC does not scan program stack for root objects so you should add roots explicitly:
let foo = Gc::new(Foo {...});
add_root(foo);
... // do something with `foo`
remove_root(foo);
// Or use `Rooted` struct that will unroot object automatically:
let foo = Rooted:new(Foo {...});
gc_mark
in your code.