Trait jrsonnet_gcmodule::Trace

source ·
pub trait Trace: 'static {
    // Provided methods
    fn trace(&self, tracer: &mut Tracer<'_>) { ... }
    fn is_type_tracked() -> bool
       where Self: Sized { ... }
}
Expand description

Defines how the cycle collector should collect a type.

§Customized Drop implementation

The Drop implementation should avoid dereferencing other [Cc<T>] objects. Failing to do so might cause panic or undefined behavior. For example, T1 has a field Cc<T2>. The collector might have already dropped T2 by the time T1::drop runs.

The Drop implementation should also be careful about cloning (resurrecting) [Cc<T>] objects. If it must do so, the trace implementation should match by avoiding visiting those cloned objects.

§The 'static bound

Types tracked by the collector can potentially be kept alive forever. Therefore types with non-static references are not allowed.

Provided Methods§

source

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

Define how to visit values referred by this value.

For example, if self.x is a value referred by self, call self.x.trace(tracer) to visit it.

The values that are visited must match the Drop::drop implementation. Otherwise memory leak or panic might happen. After the panic, dereferencing already collected Cc<T> can trigger:

  • Undefined behavior on release build.
  • Another panic on debug build.

Ideally this can be generated by the compiler, since the compiler already knows how to generate Drop::drop.

source

fn is_type_tracked() -> bool
where Self: Sized,

Whether this type should be tracked by the collector.

Types that might include Cc<T> where T can form a cycle should be tracked. This allows the collector to visit the Cc values from its parents and count references correctly.

If a type T is tracked, Cc<T> will be 3 usize larger and the collector will check them.

For example,

  • Vec<u8> is not tracked. It does include any kind of Cc<T>.
  • Box<Cc<u8>> is not tracked. It includes Cc<u8> but u8 cannot create cycles.
  • Box<dyn Trace> is tracked. The trait object can be anything, including any kinds of types that contains a Cc<T>.

Usually, concrete Rust types can opt-out the cycle collector. There are a few exceptions:

  • Trait objects, and types containing trait objects. Trait objects can be anything so they should be tracked.
  • Recursive types. Such as, struct S(RefCell<Option<Rc<Box<S>>>>). Those types need an explicit name like S, and a manual implementation of the Trace trait. That implementation should make is_type_tracked return true directly.

This is an optimization for performance. When in-doubt, return true for correctness.

Trait Implementations§

source§

impl Trace for Box<dyn Trace>

source§

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

Define how to visit values referred by this value. Read more
source§

fn is_type_tracked() -> bool

Whether this type should be tracked by the collector. Read more
source§

impl Trace for Box<dyn Trace + Send>

source§

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

Define how to visit values referred by this value. Read more
source§

fn is_type_tracked() -> bool

Whether this type should be tracked by the collector. Read more
source§

impl Trace for Box<dyn Trace + Send + Sync>

source§

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

Define how to visit values referred by this value. Read more
source§

fn is_type_tracked() -> bool

Whether this type should be tracked by the collector. Read more

Implementations on Foreign Types§

source§

impl Trace for &'static str

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for bool

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for char

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for f32

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for f64

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for i8

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for i16

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for i32

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for i64

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for isize

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for u8

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for u16

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for u32

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for u64

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for ()

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for usize

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for Box<dyn Trace + Send + Sync>

source§

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

source§

fn is_type_tracked() -> bool

source§

impl Trace for Box<dyn Trace + Send>

source§

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

source§

fn is_type_tracked() -> bool

source§

impl Trace for Box<dyn Trace>

source§

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

source§

fn is_type_tracked() -> bool

source§

impl Trace for CString

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for NulError

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for String

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for Ipv4Addr

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for Ipv6Addr

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for AddrParseError

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for SocketAddrV4

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for SocketAddrV6

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for OsString

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for TcpListener

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for TcpStream

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for UdpSocket

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for PathBuf

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for Child

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for ChildStderr

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for ChildStdin

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for ChildStdout

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for Command

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for ExitStatus

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for Output

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for Stdio

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl Trace for Thread

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, C: 'static, D: 'static, E: 'static, F: 'static, X: 'static> Trace for fn(_: A, _: B, _: C, _: D, _: E, _: F) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, C: 'static, D: 'static, E: 'static, X: 'static> Trace for fn(_: A, _: B, _: C, _: D, _: E) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, C: 'static, D: 'static, X: 'static> Trace for fn(_: &A, _: &B, _: &C, _: &D) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, C: 'static, D: 'static, X: 'static> Trace for fn(_: &A, _: &B, _: &C, _: D) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, C: 'static, D: 'static, X: 'static> Trace for fn(_: &A, _: &B, _: C, _: &D) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, C: 'static, D: 'static, X: 'static> Trace for fn(_: &A, _: &B, _: C, _: D) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, C: 'static, D: 'static, X: 'static> Trace for fn(_: &A, _: B, _: &C, _: &D) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, C: 'static, D: 'static, X: 'static> Trace for fn(_: &A, _: B, _: &C, _: D) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, C: 'static, D: 'static, X: 'static> Trace for fn(_: &A, _: B, _: C, _: &D) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, C: 'static, D: 'static, X: 'static> Trace for fn(_: &A, _: B, _: C, _: D) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, C: 'static, D: 'static, X: 'static> Trace for fn(_: A, _: &B, _: &C, _: &D) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, C: 'static, D: 'static, X: 'static> Trace for fn(_: A, _: &B, _: &C, _: D) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, C: 'static, D: 'static, X: 'static> Trace for fn(_: A, _: &B, _: C, _: &D) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, C: 'static, D: 'static, X: 'static> Trace for fn(_: A, _: &B, _: C, _: D) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, C: 'static, D: 'static, X: 'static> Trace for fn(_: A, _: B, _: &C, _: &D) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, C: 'static, D: 'static, X: 'static> Trace for fn(_: A, _: B, _: &C, _: D) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, C: 'static, D: 'static, X: 'static> Trace for fn(_: A, _: B, _: C, _: &D) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, C: 'static, D: 'static, X: 'static> Trace for fn(_: A, _: B, _: C, _: D) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, C: 'static, X: 'static> Trace for fn(_: &A, _: &B, _: &C) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, C: 'static, X: 'static> Trace for fn(_: &A, _: &B, _: C) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, C: 'static, X: 'static> Trace for fn(_: &A, _: B, _: &C) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, C: 'static, X: 'static> Trace for fn(_: &A, _: B, _: C) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, C: 'static, X: 'static> Trace for fn(_: A, _: &B, _: &C) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, C: 'static, X: 'static> Trace for fn(_: A, _: &B, _: C) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, C: 'static, X: 'static> Trace for fn(_: A, _: B, _: &C) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, C: 'static, X: 'static> Trace for fn(_: A, _: B, _: C) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, X: 'static> Trace for fn(_: &A, _: &B) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, X: 'static> Trace for fn(_: &A, _: B) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, X: 'static> Trace for fn(_: A, _: &B) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, B: 'static, X: 'static> Trace for fn(_: A, _: B) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, X: 'static> Trace for fn(_: &A) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: 'static, X: 'static> Trace for fn(_: A) -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<A: Trace> Trace for (A,)

source§

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

source§

fn is_type_tracked() -> bool

source§

impl<A: Trace, B: Trace> Trace for (A, B)

source§

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

source§

fn is_type_tracked() -> bool

source§

impl<A: Trace, B: Trace, C: Trace> Trace for (A, B, C)

source§

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

source§

fn is_type_tracked() -> bool

source§

impl<A: Trace, B: Trace, C: Trace, D: Trace> Trace for (A, B, C, D)

source§

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

source§

fn is_type_tracked() -> bool

source§

impl<A: Trace, B: Trace, C: Trace, D: Trace, E: Trace> Trace for (A, B, C, D, E)

source§

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

source§

fn is_type_tracked() -> bool

source§

impl<A: Trace, B: Trace, C: Trace, D: Trace, E: Trace, F: Trace> Trace for (A, B, C, D, E, F)

source§

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

source§

fn is_type_tracked() -> bool

source§

impl<A: Trace, B: Trace, C: Trace, D: Trace, E: Trace, F: Trace, G: Trace> Trace for (A, B, C, D, E, F, G)

source§

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

source§

fn is_type_tracked() -> bool

source§

impl<K: Eq + Hash + Trace, V: Trace> Trace for HashMap<K, V>

source§

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

source§

fn is_type_tracked() -> bool

source§

impl<K: Trace, V: Trace> Trace for BTreeMap<K, V>

source§

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

source§

fn is_type_tracked() -> bool

source§

impl<T: 'static> Trace for Rc<T>

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<T: 'static> Trace for Weak<T>

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<T: 'static> Trace for Arc<T>

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<T: 'static> Trace for PhantomData<T>

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<T: 'static> Trace for LocalKey<T>

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<T: 'static> Trace for JoinHandle<T>

source§

fn is_type_tracked() -> bool
where Self: Sized,

source§

impl<T: ToOwned + ?Sized> Trace for Cow<'static, T>
where T::Owned: Trace,

source§

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

source§

fn is_type_tracked() -> bool

source§

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

source§

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

source§

fn is_type_tracked() -> bool

source§

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

source§

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

source§

fn is_type_tracked() -> bool

source§

impl<T: Trace> Trace for Box<T>

source§

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

source§

fn is_type_tracked() -> bool

source§

impl<T: Trace> Trace for LinkedList<T>

source§

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

source§

fn is_type_tracked() -> bool

source§

impl<T: Trace> Trace for VecDeque<T>

source§

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

source§

fn is_type_tracked() -> bool

source§

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

source§

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

source§

fn is_type_tracked() -> bool

source§

impl<T: Trace> Trace for OnceCell<T>

source§

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

source§

fn is_type_tracked() -> bool

source§

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

source§

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

source§

fn is_type_tracked() -> bool

source§

impl<T: Trace> Trace for Mutex<T>

source§

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

source§

fn is_type_tracked() -> bool

source§

impl<T: Trace> Trace for RwLock<T>

source§

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

source§

fn is_type_tracked() -> bool

source§

impl<T: Trace, U: Trace> Trace for Result<T, U>

source§

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

source§

fn is_type_tracked() -> bool

source§

impl<X: 'static> Trace for fn() -> X

source§

fn is_type_tracked() -> bool
where Self: Sized,

Implementors§