diff --git a/src/multiportgraph.rs b/src/multiportgraph.rs index e502bd7..0e160b4 100644 --- a/src/multiportgraph.rs +++ b/src/multiportgraph.rs @@ -259,59 +259,28 @@ impl PortMut for MultiPortGraph { impl LinkView for MultiPortGraph { type LinkEndpoint = SubportIndex; - #[inline] - fn get_connections( - &self, - from: NodeIndex, - to: NodeIndex, - ) -> impl Iterator + Clone { - self._get_connections(from, to) - } - - #[inline] - fn port_links( - &self, - port: PortIndex, - ) -> impl Iterator + Clone { - self._port_links(port) - } - - #[inline] - fn links( - &self, - node: NodeIndex, - direction: Direction, - ) -> impl Iterator + Clone { - self._links(node, direction) - } - - #[inline] - fn all_links( - &self, - node: NodeIndex, - ) -> impl Iterator + Clone { - self._all_links(node) - } - - #[inline] - fn neighbours( - &self, - node: NodeIndex, - direction: Direction, - ) -> impl Iterator + Clone { - self._neighbours(node, direction) - } - - #[inline] - fn all_neighbours(&self, node: NodeIndex) -> impl Iterator + Clone { - self._all_neighbours(node) - } - #[inline] fn link_count(&self) -> usize { // Do not count the links between copy nodes and their main nodes. self.graph.link_count() - self.copy_node_count } + + delegate! { + to self { + #[call(_get_connections)] + fn get_connections(&self, from: NodeIndex, to: NodeIndex) -> impl Iterator + Clone; + #[call(_port_links)] + fn port_links(&self, port: PortIndex) -> impl Iterator + Clone; + #[call(_links)] + fn links(&self, node: NodeIndex, direction: Direction) -> impl Iterator + Clone; + #[call(_all_links)] + fn all_links(&self, node: NodeIndex) -> impl Iterator + Clone; + #[call(_neighbours)] + fn neighbours(&self, node: NodeIndex, direction: Direction) -> impl Iterator + Clone; + #[call(_all_neighbours)] + fn all_neighbours(&self, node: NodeIndex) -> impl Iterator + Clone; + } + } } impl LinkMut for MultiPortGraph { @@ -346,18 +315,13 @@ impl MultiView for MultiPortGraph { self.get_subport_from_index(link) } - #[inline] - fn subports( - &self, - node: NodeIndex, - direction: Direction, - ) -> impl Iterator + Clone { - self._subports(node, direction) - } - - #[inline] - fn all_subports(&self, node: NodeIndex) -> impl Iterator + Clone { - self._all_subports(node) + delegate! { + to self { + #[call(_subports)] + fn subports(&self, node: NodeIndex, direction: Direction) -> impl Iterator + Clone; + #[call(_all_subports)] + fn all_subports(&self, node: NodeIndex) -> impl Iterator + Clone; + } } } diff --git a/src/portgraph.rs b/src/portgraph.rs index 89ecd04..a01ae7e 100644 --- a/src/portgraph.rs +++ b/src/portgraph.rs @@ -12,6 +12,7 @@ mod iter; +use delegate::delegate; use std::mem::{replace, take}; use std::num::{NonZeroU16, NonZeroU32}; use std::ops::Range; @@ -352,18 +353,6 @@ impl PortView for PortGraph { node_meta.ports(direction).nth(offset).map(PortIndex::new) } - fn ports( - &self, - node: NodeIndex, - direction: Direction, - ) -> impl Iterator + Clone { - self._ports(node, direction) - } - - fn all_ports(&self, node: NodeIndex) -> impl Iterator + Clone { - self._all_ports(node) - } - #[inline] fn input(&self, node: NodeIndex, offset: usize) -> Option { self.port_index(node, PortOffset::new_incoming(offset)) @@ -385,19 +374,6 @@ impl PortView for PortGraph { } } - fn port_offsets( - &self, - node: NodeIndex, - direction: Direction, - ) -> impl Iterator + Clone { - self._port_offsets(node, direction) - } - - #[inline] - fn all_port_offsets(&self, node: NodeIndex) -> impl Iterator + Clone { - self._all_port_offsets(node) - } - #[inline] fn contains_node(&self, node: NodeIndex) -> bool { self.node_meta_valid(node).is_some() @@ -423,16 +399,6 @@ impl PortView for PortGraph { self.port_count } - #[inline] - fn nodes_iter(&self) -> impl Iterator + Clone { - self._nodes_iter() - } - - #[inline] - fn ports_iter(&self) -> impl Iterator + Clone { - self._ports_iter() - } - #[inline] fn node_capacity(&self) -> usize { self.node_meta.capacity() @@ -448,6 +414,22 @@ impl PortView for PortGraph { self.node_meta_valid(node) .map_or(0, |node_meta| node_meta.capacity()) } + delegate! { + to self { + #[call(_ports)] + fn ports(&self, node: NodeIndex, direction: Direction) -> impl Iterator + Clone; + #[call(_all_ports)] + fn all_ports(&self, node: NodeIndex) -> impl Iterator + Clone; + #[call(_port_offsets)] + fn port_offsets(&self, node: NodeIndex, direction: Direction) -> impl Iterator + Clone; + #[call(_all_port_offsets)] + fn all_port_offsets(&self, node: NodeIndex) -> impl Iterator + Clone; + #[call(_nodes_iter)] + fn nodes_iter(&self) -> impl Iterator + Clone; + #[call(_ports_iter)] + fn ports_iter(&self) -> impl Iterator + Clone; + } + } } impl PortMut for PortGraph { @@ -728,15 +710,6 @@ impl PortMut for PortGraph { impl LinkView for PortGraph { type LinkEndpoint = PortIndex; - #[inline] - fn get_connections( - &self, - from: NodeIndex, - to: NodeIndex, - ) -> impl Iterator + Clone { - self._get_connections(from, to) - } - fn port_links(&self, port: PortIndex) -> impl Iterator + Clone { self.port_meta_valid(port).unwrap(); match self.port_link[port.index()] { @@ -749,39 +722,25 @@ impl LinkView for PortGraph { } } - fn links( - &self, - node: NodeIndex, - direction: Direction, - ) -> impl Iterator + Clone { - self._links(node, direction) - } - - fn all_links( - &self, - node: NodeIndex, - ) -> impl Iterator + Clone { - self._all_links(node) - } - - #[inline] - fn neighbours( - &self, - node: NodeIndex, - direction: Direction, - ) -> impl Iterator + Clone { - self._neighbours(node, direction) - } - - #[inline] - fn all_neighbours(&self, node: NodeIndex) -> impl Iterator + Clone { - self._all_neighbours(node) - } - #[inline] fn link_count(&self) -> usize { self.link_count } + + delegate! { + to self { + #[call(_get_connections)] + fn get_connections(&self, from: NodeIndex, to: NodeIndex) -> impl Iterator + Clone; + #[call(_links)] + fn links(&self, node: NodeIndex, direction: Direction) -> impl Iterator + Clone; + #[call(_all_links)] + fn all_links(&self, node: NodeIndex) -> impl Iterator + Clone; + #[call(_neighbours)] + fn neighbours(&self, node: NodeIndex, direction: Direction) -> impl Iterator + Clone; + #[call(_all_neighbours)] + fn all_neighbours(&self, node: NodeIndex) -> impl Iterator + Clone; + } + } } impl LinkMut for PortGraph {