Skip to content

Commit

Permalink
Remove Port::new_{incom,outgo}ing
Browse files Browse the repository at this point in the history
  • Loading branch information
acl-cqc committed Oct 20, 2023
1 parent 1e9912d commit f30ae99
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 24 deletions.
24 changes: 6 additions & 18 deletions src/hugr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,14 +387,6 @@ impl Port {
}
}

/// Creates a new incoming port.
#[inline]
pub fn new_incoming(port: impl Into<IncomingPort>) -> Self {
Self {
offset: portgraph::PortOffset::new_incoming(port.into().index()),
}
}

/// Converts to an [IncomingPort] if this port is one; else fails with
/// [HugrError::InvalidPortDirection]
#[inline]
Expand All @@ -407,14 +399,6 @@ impl Port {
}
}

/// Creates a new outgoing port.
#[inline]
pub fn new_outgoing(port: impl Into<OutgoingPort>) -> Self {
Self {
offset: portgraph::PortOffset::new_outgoing(port.into().index()),
}
}

/// Converts to an [OutgoingPort] if this port is one; else fails with
/// [HugrError::InvalidPortDirection]
#[inline]
Expand Down Expand Up @@ -492,13 +476,17 @@ impl From<usize> for OutgoingPort {

impl From<IncomingPort> for Port {
fn from(value: IncomingPort) -> Self {
Port::new_incoming(value)
Self {
offset: portgraph::PortOffset::new_incoming(value.index()),
}
}
}

impl From<OutgoingPort> for Port {
fn from(value: OutgoingPort) -> Self {
Port::new_outgoing(value)
Self {
offset: portgraph::PortOffset::new_outgoing(value.index()),
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/hugr/hugrmut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,9 @@ impl<T: RootTagged<RootHandle = Node> + AsMut<Hugr>> HugrMut for T {
) -> Result<(), HugrError> {
self.as_mut().graph.link_nodes(
src.index,
Port::new_outgoing(src_port).index(),
src_port.into().index(),
dst.index,
Port::new_incoming(dst_port).index(),
dst_port.into().index(),
)?;
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions src/hugr/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ pub mod test {
use super::*;
use crate::extension::{EMPTY_REG, PRELUDE_REGISTRY};
use crate::hugr::hugrmut::sealed::HugrMutInternals;
use crate::hugr::OutgoingPort;
use crate::{
builder::{
test::closed_dfg_root_hugr, Container, DFGBuilder, Dataflow, DataflowHugr,
Expand All @@ -283,7 +284,6 @@ pub mod test {
hugr::NodeType,
ops::{dataflow::IOTrait, Input, LeafOp, Module, Output, DFG},
types::{FunctionType, Type},
Port,
};
use itertools::Itertools;
use portgraph::{
Expand Down Expand Up @@ -466,7 +466,7 @@ pub mod test {

// Now add a new input
let new_in = hugr.add_op(Input::new([QB].to_vec()));
hugr.disconnect(old_in, Port::new_outgoing(0)).unwrap();
hugr.disconnect(old_in, OutgoingPort::from(0)).unwrap();
hugr.connect(new_in, 0, out, 0).unwrap();
hugr.move_before_sibling(new_in, old_in).unwrap();
hugr.remove_node(old_in).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src/hugr/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ mod test {
Extension, ExtensionId, ExtensionSet, TypeDefBound, EMPTY_REG, PRELUDE_REGISTRY,
};
use crate::hugr::hugrmut::sealed::HugrMutInternals;
use crate::hugr::{HugrError, HugrMut, NodeType};
use crate::hugr::{HugrError, HugrMut, IncomingPort, NodeType};
use crate::macros::const_extension_ids;
use crate::ops::dataflow::IOTrait;
use crate::ops::{self, LeafOp, OpType};
Expand Down Expand Up @@ -1146,7 +1146,7 @@ mod test {
h.update_validate(&EMPTY_REG),
Err(ValidationError::UnconnectedPort {
node: and,
port: Port::new_incoming(1),
port: IncomingPort::from(1).into(),
port_kind: EdgeKind::Value(BOOL_T)
})
);
Expand Down

0 comments on commit f30ae99

Please sign in to comment.