Trait sdd::Collectible

source ·
pub trait Collectible {
    // Required method
    fn next_ptr_mut(&mut self) -> &mut Option<NonNull<dyn Collectible>>;
}
Expand description

Collectible defines the memory layout for the type in order to be passed to the garbage collector.

§Examples

use sdd::{Collectible, Guard};
use std::ptr::NonNull;

struct LazyString(String, Option<NonNull<dyn Collectible>>);

impl Collectible for LazyString {
    fn next_ptr_mut(&mut self) -> &mut Option<NonNull<dyn Collectible>> {
        &mut self.1
    }
}

let boxed: Box<LazyString> = Box::new(LazyString(String::from("Lazy"), None));

let static_ref: &'static LazyString = unsafe { std::mem::transmute(&*boxed) };
let guard_for_ref = Guard::new();

let guard_to_drop = Guard::new();
guard_to_drop.defer(boxed);
drop(guard_to_drop);

// The reference is valid as long as a `Guard` that had been created before `boxed` was
// passed to a `Guard` survives.
assert_eq!(static_ref.0, "Lazy");

Required Methods§

source

fn next_ptr_mut(&mut self) -> &mut Option<NonNull<dyn Collectible>>

Returns a mutable reference to the next Collectible pointer.

Implementors§