-
Notifications
You must be signed in to change notification settings - Fork 7
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
refactor: Nonempty #902
refactor: Nonempty #902
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #902 +/- ##
==========================================
- Coverage 85.63% 85.56% -0.08%
==========================================
Files 78 78
Lines 14444 14415 -29
Branches 14444 14415 -29
==========================================
- Hits 12369 12334 -35
- Misses 1436 1443 +7
+ Partials 639 638 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
pub fn nodes(&self) -> &NonEmpty<Node> { | ||
&self.nodes |
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.
I'd prefer to leave the NonEmpty
out of the public interface here,
pub fn nodes(&self) -> &NonEmpty<Node> { | |
&self.nodes | |
pub fn nodes<'a>(&'a self) -> impl Iterator<Item = &'a Node> + &'a { | |
self.nodes.iter() |
that breaks some code, you'll need some collect_vec
s around (which implies allocating new arrays :/).
So something like
let portgraph: NodeFiltered<_, NodeFilter<Vec<Node>>, Vec<Node>> =
NodeFiltered::new_node_filtered(
other.portgraph(),
|node, ctx| ctx.contains(&node.into()),
subgraph.nodes().cloned().collect_vec(),
);
in HugrMut::insert_subgraph
.
@@ -59,7 +59,7 @@ pub struct Replacement { | |||
/// These must all have a common parent (i.e. be siblings). Called "S" in the spec. | |||
/// Must be non-empty - otherwise there is no parent under which to place [Self::replacement], | |||
/// and there would be no possible [Self::mu_inp], [Self::mu_out] or [Self::adoptions]. | |||
pub removal: Vec<Node>, | |||
pub removal: NonEmpty<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.
This requires every dependent to add a direct dependency on NonEmpty
. Although it's nice to statically check this internally, i'd prefer the external interface be left more generic.
Adding a Replacement::try_new(removel: Vec<Node>, ...)
could help with this.
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.
fair enough
Hey, we'll close this for now as it requires exposing transitive dependencies in the public API. Thanks nonetheless for suggesting the change :) |
Replacements and SiblingSubgraph have nonempty vecs upon construction. Attempting to create them with empty vecs gives errors (InvalidSubgraph::EmptySubgraph) so following "illegal state unrepresentable".