Skip to main content

runmat_gc_api/
root.rs

1use crate::GcHandle;
2
3/// Unique identifier for a registered GC root source.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5pub struct RootId(pub usize);
6
7/// Source of GC handles that must be treated as roots during collection.
8pub trait GcRoot {
9    /// Scan this root source and return all reachable GC handles.
10    fn scan(&self) -> Vec<GcHandle>;
11
12    /// Get a human-readable description of this root source.
13    fn description(&self) -> String;
14
15    /// Get the estimated size of values reachable from this root source.
16    fn estimated_size(&self) -> usize {
17        0
18    }
19
20    /// Check if this root source is still active.
21    fn is_active(&self) -> bool {
22        true
23    }
24}
25
26/// Information about a registered root source.
27#[derive(Debug, Clone)]
28pub struct RootInfo {
29    pub id: RootId,
30    pub description: String,
31    pub estimated_size: usize,
32    pub is_active: bool,
33}
34
35/// Statistics for root scanning.
36#[derive(Debug, Clone)]
37pub struct RootScannerStats {
38    pub registered_roots: usize,
39    pub scans_performed: usize,
40    pub total_roots_found: usize,
41    pub average_roots_per_scan: f64,
42}