Skip to main content

Tracer

Struct Tracer 

Source
pub struct Tracer<'a> { /* private fields */ }
Expand description

The sink a Trace implementation reports its outgoing edges to.

A Tracer is handed to Trace::trace during a collection. Its one job is to receive handles: each call to mark records that the object being traced points at another, so the collector can visit it in turn. It holds a borrow of the collector’s work queue and nothing else, so recording an edge is a single push — no allocation on the steady-state path, since the queue is reused across collections.

You never construct a Tracer; the heap builds one and passes it in.

Implementations§

Source§

impl<'a> Tracer<'a>

Source

pub fn mark<T>(&mut self, handle: Gc<T>)

Records that the object being traced holds handle, so the collector will visit — and thereby keep alive — the object it names.

Call this once for every handle the object owns. Marking a handle that does not name a live object is harmless: the collector rejects it when it reaches the front of the queue. The generic parameter lets a value mix handles into several heaps; each is validated against its own heap when that heap collects.

§Examples
use gc_lang::{Gc, Trace, Tracer};

struct Cell {
    next: Option<Gc<Cell>>,
}

impl Trace for Cell {
    fn trace(&self, tracer: &mut Tracer<'_>) {
        if let Some(next) = self.next {
            tracer.mark(next);
        }
    }
}

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for Tracer<'a>

§

impl<'a> Freeze for Tracer<'a>

§

impl<'a> RefUnwindSafe for Tracer<'a>

§

impl<'a> Send for Tracer<'a>

§

impl<'a> Sync for Tracer<'a>

§

impl<'a> Unpin for Tracer<'a>

§

impl<'a> UnsafeUnpin for Tracer<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.