diff --git a/README.md b/README.md index 3a3fbf1..0a54418 100644 --- a/README.md +++ b/README.md @@ -4,35 +4,32 @@ An easy-to-use, incremental, multi-threaded garbage collector for Rust. ```rust //! A basic usage example demonstrating the garbage collector. -use refuse::{collected, CollectionGuard, Ref, Root}; - -#[collected] -fn main() { - let guard = CollectionGuard::acquire(); - // Allocate a vec![Ref(1), Ref(2), Ref(3)]. - let values: Vec> = (1..=3).map(|value| Ref::new(value, &guard)).collect(); - let values = Root::new(values, &guard); - drop(guard); - - // Manually execute the garbage collector. Our data will not be freed, - // since `values` is a "root" reference. - refuse::collect(); - - // Root references allow direct access to their data, even when a - // `CollectionGuard` isn't held. - let (one, two, three) = (values[0], values[1], values[2]); - - // Accessing the data contained in a `Ref` requires a guard, however. - let mut guard = CollectionGuard::acquire(); - assert_eq!(one.load(&guard), Some(&1)); - assert_eq!(two.load(&guard), Some(&2)); - assert_eq!(three.load(&guard), Some(&3)); - - // Dropping our root will allow the collector to free our `Ref`s. - drop(values); - guard.collect(); - assert_eq!(one.load(&guard), None); -} +use refuse::{CollectionGuard, Ref, Root}; + +let guard = CollectionGuard::acquire(); +// Allocate a vec![Ref(1), Ref(2), Ref(3)]. +let values: Vec> = (1..=3).map(|value| Ref::new(value, &guard)).collect(); +let values = Root::new(values, &guard); +drop(guard); + +// Manually execute the garbage collector. Our data will not be freed, +// since `values` is a "root" reference. +refuse::collect(); + +// Root references allow direct access to their data, even when a +// `CollectionGuard` isn't held. +let (one, two, three) = (values[0], values[1], values[2]); + +// Accessing the data contained in a `Ref` requires a guard, however. +let mut guard = CollectionGuard::acquire(); +assert_eq!(one.load(&guard), Some(&1)); +assert_eq!(two.load(&guard), Some(&2)); +assert_eq!(three.load(&guard), Some(&3)); + +// Dropping our root will allow the collector to free our `Ref`s. +drop(values); +guard.collect(); +assert_eq!(one.load(&guard), None); ``` As the version number indicates, this crate is in early development. No semver diff --git a/benchmarks/benches/timings.rs b/benchmarks/benches/timings.rs index e4126e5..7596c9c 100644 --- a/benchmarks/benches/timings.rs +++ b/benchmarks/benches/timings.rs @@ -4,7 +4,7 @@ use std::convert::Infallible; use std::hint::black_box; use std::sync::Arc; -use refuse::{collected, CollectionGuard, Ref, Root}; +use refuse::{CollectionGuard, Ref, Root}; use timings::{Benchmark, BenchmarkImplementation, Label, LabeledTimings, Timings}; const TOTAL_ITERS: usize = 100_000; @@ -105,21 +105,20 @@ impl BenchmarkImplementation for GcRef { fn measure(&mut self, measurements: &LabeledTimings