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§
Provided Methods§
Sourcefn external_bytes(&self) -> usize
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<T: Trace + ?Sized> Trace for &T
impl<T: Trace + ?Sized> Trace for &T
Source§fn external_bytes(&self) -> usize
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.