-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: Add associated type Node to HugrView #1932
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1932 +/- ##
==========================================
- Coverage 83.70% 83.69% -0.02%
==========================================
Files 196 196
Lines 37543 37691 +148
Branches 34356 34504 +148
==========================================
+ Hits 31425 31545 +120
- Misses 4335 4360 +25
- Partials 1783 1786 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
This PR contains breaking changes to the public Rust API. cargo-semver-checks summary
|
b86da46
to
1a24227
Compare
@doug-q for I'm sure it would be easy to change but I don't think we need to support more general |
58b76ae
to
2528fb7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
pub trait HugrNode: Copy + Ord + std::fmt::Debug + std::fmt::Display + std::hash::Hash {} | ||
|
||
impl<T: Copy + Ord + std::fmt::Debug + std::fmt::Display + std::hash::Hash> HugrNode for T {} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason we don't have to_pg_index
and to_node
in the HugrNode
trait instead of HugrInternals
is that we need context to create one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'm expecting that node types that are made of (node id, hugr id) pairs might map in different ways to NodeIndex (otherwise might as well stick with Node)
hugr-core/src/hugr/internal.rs
Outdated
/// Convert a node to a portgraph node index. | ||
fn to_pg_index(&self, node: Self::Node) -> portgraph::NodeIndex; | ||
|
||
/// Convert a portgraph node index to a node. | ||
fn to_node(&self, index: portgraph::NodeIndex) -> Self::Node; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally to_*
methods convert the whole struct into something else.
Here it may be more rusty to have get_node
/get_pg_index
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, will rename!
closes #1927
Yey, this is a fun one 🫠
This makes
HugrView
general over theNode
type. Note thatHugrMut
and all operations that mutate hugrs still only act on the node typeNode
.I suggest once this is merged in that we add a
.git-blame-ignore-revs
file to simplify future git blames:BREAKING CHANGE:
HugrView
now has aNode
associated type. Make your code generic over the node type where you can, replacingNode
withH::Node
. Otherwise, use the type boundH: HugrView<Node = Node>
.