Skip to main content

Trace

Trait Trace 

Source
pub trait Trace {
    // Required method
    fn trace(&self, tracer: &mut Tracer<'_>);

    // Provided method
    fn external_bytes(&self) -> usize { ... }
}
Expand description

Types that may own Gc handles.

Implementations must visit every Gc field, directly or through another type that implements Trace. Missing an edge makes the collector treat the object as unreachable from that side, which only costs memory (a cycle that is never reclaimed), never safety — but it is still a bug.

Required Methods§

Source

fn trace(&self, tracer: &mut Tracer<'_>)

Report every Gc owned by self to tracer.

Provided Methods§

Source

fn external_bytes(&self) -> usize

Bytes this value owns outside its own box: a string’s buffer, an array’s element vector, a buffer’s bytes.

Without this, a memory limit would be counting the box a container lives in and missing everything inside it — var a = []; for (;;) a.push(1.5) allocates one box and then gigabytes of element slots, so the limit would never trip. The default is zero, which is right for everything that is only a box: numbers, symbols, cells, compiled code.

Read in three places, all of them at allocation boundaries rather than in a loop: on allocation (added), on free (subtracted, so nothing leaks out of the accounting) and when a container grows or shrinks in place (adjusted by the container itself).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Trace for &'static str

Source§

fn trace(&self, _tracer: &mut Tracer<'_>)

Source§

impl Trace for ()

Source§

fn trace(&self, _tracer: &mut Tracer<'_>)

Source§

impl Trace for String

Source§

fn trace(&self, _tracer: &mut Tracer<'_>)

Source§

impl Trace for bool

Source§

fn trace(&self, _tracer: &mut Tracer<'_>)

Source§

impl Trace for char

Source§

fn trace(&self, _tracer: &mut Tracer<'_>)

Source§

impl Trace for f32

Source§

fn trace(&self, _tracer: &mut Tracer<'_>)

Source§

impl Trace for f64

Source§

fn trace(&self, _tracer: &mut Tracer<'_>)

Source§

impl Trace for i8

Source§

fn trace(&self, _tracer: &mut Tracer<'_>)

Source§

impl Trace for i16

Source§

fn trace(&self, _tracer: &mut Tracer<'_>)

Source§

impl Trace for i32

Source§

fn trace(&self, _tracer: &mut Tracer<'_>)

Source§

impl Trace for i64

Source§

fn trace(&self, _tracer: &mut Tracer<'_>)

Source§

impl Trace for i128

Source§

fn trace(&self, _tracer: &mut Tracer<'_>)

Source§

impl Trace for isize

Source§

fn trace(&self, _tracer: &mut Tracer<'_>)

Source§

impl Trace for u8

Source§

fn trace(&self, _tracer: &mut Tracer<'_>)

Source§

impl Trace for u16

Source§

fn trace(&self, _tracer: &mut Tracer<'_>)

Source§

impl Trace for u32

Source§

fn trace(&self, _tracer: &mut Tracer<'_>)

Source§

impl Trace for u64

Source§

fn trace(&self, _tracer: &mut Tracer<'_>)

Source§

impl Trace for u128

Source§

fn trace(&self, _tracer: &mut Tracer<'_>)

Source§

impl Trace for usize

Source§

fn trace(&self, _tracer: &mut Tracer<'_>)

Source§

impl<T, U> Trace for (T, U)
where T: Trace, U: Trace,

Source§

fn trace(&self, tracer: &mut Tracer<'_>)

Source§

impl<T, const N: usize> Trace for [T; N]
where T: Trace,

Source§

fn trace(&self, tracer: &mut Tracer<'_>)

Source§

impl<T> Trace for &T
where T: Trace + ?Sized,

Source§

fn external_bytes(&self) -> usize

Forwarded, and not for symmetry: without this, value.external_bytes() inside [payload_impl] — where value: &T — resolves to this impl and answers the default 0, silently. A 2 MB string then reported 0 bytes and the memory limit did not exist. Every blanket impl below forwards for the same reason.

Source§

fn trace(&self, tracer: &mut Tracer<'_>)

Source§

impl<T> Trace for Box<T>
where T: Trace + ?Sized,

Source§

fn trace(&self, tracer: &mut Tracer<'_>)

Source§

fn external_bytes(&self) -> usize

Source§

impl<T> Trace for Cell<T>
where T: Trace + Copy,

Source§

fn trace(&self, tracer: &mut Tracer<'_>)

Source§

impl<T> Trace for Option<T>
where T: Trace,

Source§

fn trace(&self, tracer: &mut Tracer<'_>)

Source§

impl<T> Trace for Rc<T>
where T: Trace,

Source§

fn trace(&self, tracer: &mut Tracer<'_>)

Source§

impl<T> Trace for RefCell<T>
where T: Trace,

Source§

fn trace(&self, tracer: &mut Tracer<'_>)

Source§

impl<T> Trace for Vec<T>
where T: Trace,

Source§

fn trace(&self, tracer: &mut Tracer<'_>)

Implementors§