#![allow(dead_code)]
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use graphrefly_core::{
BindingBoundary, Core, DepBatch, FnId, FnResult, HandleId, NodeId, OwnedCore,
};
use graphrefly_graph::Graph;
pub struct StubBinding {
pub retains: AtomicUsize,
}
impl StubBinding {
pub fn new() -> Arc<Self> {
Arc::new(Self {
retains: AtomicUsize::new(0),
})
}
}
impl BindingBoundary for StubBinding {
fn invoke_fn(&self, _node_id: NodeId, _fn_id: FnId, dep_data: &[DepBatch]) -> FnResult {
dep_data
.first()
.map_or(FnResult::Noop { tracked: None }, |db| FnResult::Data {
handle: db.latest(),
tracked: None,
})
}
fn custom_equals(&self, _: FnId, a: HandleId, b: HandleId) -> bool {
a == b
}
fn release_handle(&self, _h: HandleId) {
self.retains.fetch_sub(1, Ordering::Relaxed);
}
fn retain_handle(&self, _h: HandleId) {
self.retains.fetch_add(1, Ordering::Relaxed);
}
}
pub fn binding() -> Arc<dyn BindingBoundary> {
StubBinding::new()
}
pub struct Rt {
rt: OwnedCore,
}
impl Rt {
#[must_use]
pub fn core(&self) -> &Core {
self.rt.core()
}
}
#[must_use]
pub fn graph(name: &str) -> (Rt, Graph) {
let rt = Rt {
rt: OwnedCore::new(binding()),
};
(rt, Graph::new(name))
}
#[must_use]
pub fn graph_with(name: &str, binding: Arc<dyn BindingBoundary>) -> (Rt, Graph) {
let rt = Rt {
rt: OwnedCore::new(binding),
};
(rt, Graph::new(name))
}