mod mark_sweep;
mod ptr;
mod root_ptr;
use crate::TypeMemory;
use std::marker::PhantomData;
pub use mark_sweep::MarkSweep;
pub use ptr::{GcPtr, HasIndirectionPtr, RawGcPtr};
pub use root_ptr::GcRootPtr;
#[derive(Debug, Clone, Default)]
pub struct Stats {
pub allocated_memory: usize,
}
pub trait TypeTrace: Send + Sync {
type Trace: Iterator<Item = GcPtr>;
fn trace(&self, obj: GcPtr) -> Self::Trace;
}
pub trait GcRuntime<T: TypeMemory + TypeTrace>: Send + Sync {
fn alloc(&self, ty: T) -> GcPtr;
fn ptr_type(&self, obj: GcPtr) -> T;
fn root(&self, obj: GcPtr);
fn unroot(&self, obj: GcPtr);
fn stats(&self) -> Stats;
}
pub trait Observer: Send + Sync {
type Event;
fn event(&self, _event: Self::Event) {}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Event {
Allocation(GcPtr),
Start,
Deallocation(GcPtr),
End,
}
#[derive(Clone)]
pub struct NoopObserver<T: Send + Sync> {
data: PhantomData<T>,
}
impl<T: Send + Sync> Observer for NoopObserver<T> {
type Event = T;
}
impl<T: Send + Sync> Default for NoopObserver<T> {
fn default() -> Self {
NoopObserver { data: PhantomData }
}
}