Skip to content
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

Add trait impls for refs #94

Merged
merged 3 commits into from
Jul 26, 2023
Merged

Add trait impls for refs #94

merged 3 commits into from
Jul 26, 2023

Conversation

lmondada
Copy link
Contributor

@lmondada lmondada commented Jul 25, 2023

Closes #93

@lmondada
Copy link
Contributor Author

@aborgna-q What do you think of this solution? Do you see a less verbose way? We'd have to do the same for &mut for both mutable and immutable types...

The better solution would probably to fix auto_impl to support GATs (if that is really the problem), but I don't have time to do that now.

@lmondada lmondada requested a review from aborgna-q July 25, 2023 12:36
@aborgna-q
Copy link
Collaborator

aborgna-q commented Jul 25, 2023

  • I'm ok with adding this, but what's your usecase?
  • You could use delegate! to reduce the boilerplate. (And also makes sure to add all the #[inline]s).
    delegate! {
        to (*self) {
            fn port_direction(&self, port: impl Into<PortIndex>) -> Option<Direction>;
            fn port_node(&self, port: impl Into<PortIndex>) -> Option<NodeIndex>;
            ...
        }
    }

(see filter.rs)

@lmondada
Copy link
Contributor Author

lmondada commented Jul 25, 2023

I have a matcher trait with the following method

trait Matcher<G: GraphBase> {
    fn find_rooted_matches(&self, G, root: <G as GraphBase>::NodeId);

    fn find_matches(&self, G) where G: petgraph::visit::IntoNodeIndices {
        // some code that requires petgraph::visit::IntoNodeIndices
    }
}

For the implemenation, it's nicer to write

impl<G> Matcher<G> for SinglePatternMatcher<U, (), UnweightedEdge>
where
    G: LinkView + GraphBase<NodeId = NodeIndex> + IntoNodeIndices
{ ... }

rather than

impl<'g, G> Matcher<&'g G> for SinglePatternMatcher<U, (), UnweightedEdge>
where
    G: LinkView
    &G: GraphBase<NodeId = NodeIndex> + IntoNodeIndices
{ ... }

(if that syntax is even valid?)

Does that make sense?

@aborgna-q
Copy link
Collaborator

s/IntoNodeIndices/IntoNodeIdentifiers/.

It may be annoying to write if you ever have a generic Matcher, but I think that'll work.

@lmondada lmondada marked this pull request as ready for review July 25, 2023 14:47
Copy link
Collaborator

@aborgna-q aborgna-q left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lmondada lmondada merged commit 9686323 into CQCL:main Jul 26, 2023
@lmondada lmondada deleted the feature/pet-impls branch July 26, 2023 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement more petgraph traits
2 participants