Use a struct for NodeGraph
This commit is contained in:
parent
7c554f731a
commit
d8f2a393ba
@ -10,12 +10,26 @@ use std::cell::{Cell, RefCell};
|
||||
use std::collections::HashMap;
|
||||
use std::collections::VecDeque;
|
||||
use std::future::Future;
|
||||
use std::ops::Deref;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::pin::Pin;
|
||||
use std::rc::Rc;
|
||||
|
||||
// TODO: consider using a struct for this, because generic bounds of type aliases aren't enforced
|
||||
type NodeGraph<S: Synchronicity> = StableDiGraph<ErasedNode<S>, (), u32>;
|
||||
// use a struct for this, not a type alias, because generic bounds of type aliases aren't enforced
|
||||
struct NodeGraph<S: Synchronicity>(StableDiGraph<ErasedNode<S>, (), u32>);
|
||||
|
||||
impl<S: Synchronicity> Deref for NodeGraph<S> {
|
||||
type Target = StableDiGraph<ErasedNode<S>, (), u32>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: Synchronicity> DerefMut for NodeGraph<S> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Synchronicity: 'static {
|
||||
type UpdateFn;
|
||||
@ -75,7 +89,7 @@ pub struct Graph<Output, Synch: Synchronicity> {
|
||||
impl<Output: Clone + 'static> Graph<Output, Synchronous> {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
node_graph: Rc::new(RefCell::new(StableDiGraph::new())),
|
||||
node_graph: Rc::new(RefCell::new(NodeGraph(StableDiGraph::new()))),
|
||||
output: None,
|
||||
output_type: std::marker::PhantomData,
|
||||
}
|
||||
@ -85,7 +99,7 @@ impl<Output: Clone + 'static> Graph<Output, Synchronous> {
|
||||
impl<Output: Clone + 'static> Graph<Output, Asynchronous> {
|
||||
pub fn new_async() -> Self {
|
||||
Self {
|
||||
node_graph: Rc::new(RefCell::new(StableDiGraph::new())),
|
||||
node_graph: Rc::new(RefCell::new(NodeGraph(StableDiGraph::new()))),
|
||||
output: None,
|
||||
output_type: std::marker::PhantomData,
|
||||
}
|
||||
@ -157,7 +171,7 @@ impl<O: Clone + 'static, S: Synchronicity> Graph<O, S> {
|
||||
util::remove_nodes_not_connected_to(&mut *graph, output);
|
||||
drop(graph);
|
||||
|
||||
let sorted = petgraph::algo::toposort(&*self.node_graph.borrow(), None);
|
||||
let sorted = petgraph::algo::toposort(&**self.node_graph.borrow(), None);
|
||||
if let Err(_cycle) = sorted {
|
||||
self.node_graph.borrow_mut().clear_edges();
|
||||
// TODO: actually build a vec describing the cycle path for debugging
|
||||
|
Loading…
x
Reference in New Issue
Block a user