Skip to content

Conversation

@cactusdualcore
Copy link
Contributor

@cactusdualcore cactusdualcore commented Jul 18, 2025

The function 'zip' was introduced in #747 as a part of adding no_std support. However, there is already such a function in core::iter. The MSRV stated in the description of #747 was 1.64 at minimum, but the function in core is stable since Rust 1.59. Thus, it is an unnecessary duplication and can be removed without consequences.

The function 'zip' was introduced in petgraph#747 as a part of adding `no_std`
support. However, there is already such a function in `core::iter`.
The MSRV stated in the description of petgraph#747 was 1.64 at minimum, but the
function in `core` is stable since Rust 1.59. Thus, it is an unnecessary
duplication and can be removed without consequences.
@cactusdualcore
Copy link
Contributor Author

There is, unfortunately, no core::iter::enumerate or std::iter::enumerate function. If it is still wanted to remove the utils.rs file, I'd be happy to do that in another PR.

@RaoulLuque RaoulLuque added A-crate Area: Petgraph crate functionality C-refactor Category: PR/issue with specific code/suggestions for refactoring S-waiting-on-review Status: Awaiting review from the assignee but also other interested parties labels Jul 20, 2025
@RaoulLuque
Copy link
Member

LGTM 👍 Let's see what the tests say :)

@RaoulLuque
Copy link
Member

RaoulLuque commented Jul 20, 2025

There is, unfortunately, no core::iter::enumerate or std::iter::enumerate function. If it is still wanted to remove the utils.rs file, I'd be happy to do that in another PR.

I see, what would be your idea then on how to get rid of the utils.rs file?

@RaoulLuque RaoulLuque self-requested a review July 20, 2025 20:23
@cactusdualcore
Copy link
Contributor Author

I see, what would be your idea then on how to get rid of the utils.rs file?

Removing the utils.rs file is synonymous with (re-)moving the definition of enumerate in it, because that's all it contains, right? I think there are three options, from imho worst to best:

  1. Put it in every file that uses it. No imports, but otherwise pretty stupid.
  2. Use the IntoIter postfix form. I think its a shame that this is such an ugly piece of code for what is a fairly common pattern.
  3. Put enumerate in lib.rs, or anywhere else than in this otherwise empty file.

I would implement the third option, i.e. moving it to wherever it fits best, and delete that file in my PR.

BONUS OPTION: open an issue on the rustlang repository to add it to the core lib. It feels like a fairly useful function with really no maintenance to include it. If core::zip exists, why shouldn't this?

cactusdualcore pushed a commit to cactusdualcore/petgraph that referenced this pull request Jul 21, 2025
The file `util.rs` contained only a single helper function for use in
the `graph_impl` module. This commit changes four (and only four) small
things to remove this file:
  1. add a replacement helper function to `src/graph_impl/mod.rs`
  2. point `src/graph_impl/mod.rs` and its submodule
     `src/graph_impl/stable_graph/mod.rs` to use the new function.
  3. remove the `mod util;` line from the crate root.
  4. remove the `src/util.rs` file from the repository.

Refs: petgraph#849
@cactusdualcore
Copy link
Contributor Author

Done!

It's actually a fairly tiny change, because the enumerate function is only used in two files. Put it in the graph_impl module now.

Given how infrequent of a pattern this actually was, you should consider just .into_iter().enumerate()-ing, I think.

I have renamed the PR to reflect this second change.

@cactusdualcore cactusdualcore changed the title refactor: replace uses of 'core::iter::zip' with 'crate::util::zip' refactor: remove util.rs file, because it is redundant Jul 21, 2025
@RaoulLuque
Copy link
Member

I see, thanks for the explanation :) I think I'd also lean towards just removing the helper function altogether and just .into_iter().enumerate()-ing everything, as what is does is already quite self-explanatory and a reasonable amount of code 🤔

@cactusdualcore
Copy link
Contributor Author

@RaoulLuque Do you want me remove the helper function in this PR, or would you a prefer a second PR to do so?

@RaoulLuque
Copy link
Member

As you wish, I'd say :) But if you split it into two, I would reduce this one to simply introducing the zip from the std and revert the removal of the util.rs file and move that into the other PR I think :)

@cactusdualcore
Copy link
Contributor Author

Ok. I think I will do two PRs then! Thanks for your fast and in-detail feedback!

I'll try getting this PR done today, but I might take a few days to start on the second.

@cactusdualcore
Copy link
Contributor Author

This PR should not include the more recent command anymore and be just the replacing of zip. Feel free to rerun the tests and then merge. I'll probably open a new PR in the next few days.

Have a nice evening!

@cactusdualcore cactusdualcore changed the title refactor: remove util.rs file, because it is redundant refactor: replace uses of 'core::iter::zip' with 'crate::util::zip' Jul 21, 2025
@RaoulLuque
Copy link
Member

Okay, great, thanks a lot :)

@RaoulLuque RaoulLuque changed the title refactor: replace uses of 'core::iter::zip' with 'crate::util::zip' refactor: replace uses of 'crate::util::zip' with 'core::iter::zip' Jul 22, 2025
@RaoulLuque
Copy link
Member

RaoulLuque commented Jul 22, 2025

I think the title was reversed, so I switched it up ^^

Side note: Just noticed, you're also from RWTH :)

@RaoulLuque RaoulLuque added this pull request to the merge queue Jul 26, 2025
Merged via the queue into petgraph:master with commit 3605788 Jul 26, 2025
28 checks passed
@github-actions github-actions bot mentioned this pull request Jul 13, 2025
BryanCruz pushed a commit to BryanCruz/petgraph that referenced this pull request Jul 26, 2025
…etgraph#849)

The function 'zip' was introduced in petgraph#747 as a part of adding `no_std`
support. However, there is already such a function in `core::iter`. The
MSRV stated in the description of petgraph#747 was 1.64 at minimum, but the
function in `core` is stable since Rust 1.59. Thus, it is an unnecessary
duplication and can be removed without consequences.

<!--
  -- Thanks for contributing to `petgraph`! 
  --
-- We require PR titles to follow the Conventional Commits
specification,
-- https://www.conventionalcommits.org/en/v1.0.0/. This helps us
generate
  -- changelogs and follow semantic versioning.
  --
  -- Start the PR title with one of the following:
  --  * `feat:` for new features
  --  * `fix:` for bug fixes
  --  * `refactor:` for code refactors
  --  * `docs:` for documentation changes
  --  * `test:` for test changes
  --  * `perf:` for performance improvements
  --  * `revert:` for reverting changes
  --  * `ci:` for CI/CD changes
-- * `chore:` for changes that don't fit in any of the above categories
  -- The last two categories will not be included in the changelog.
  --
-- If your PR includes a breaking change, please add a `!` after the
type
-- and include a `BREAKING CHANGE:` line in the body of the PR
describing
  -- the necessary changes for users to update their code.
  --
  -->

Co-authored-by: cactusdualcore <cactusdualcore@noreply.codeberg.org>
cactusdualcore added a commit to cactusdualcore/petgraph that referenced this pull request Aug 21, 2025
This was discussed in an earlier PR and removes `util.rs` and the `enumerate` function in that file.

Refs: petgraph#849
@cactusdualcore
Copy link
Contributor Author

Ok. I think I will do two PRs then! Thanks for your fast and in-detail feedback!

I'll try getting this PR done today, but I might take a few days to start on the second.

The second PR is #872

RaoulLuque pushed a commit to RaoulLuque/petgraph that referenced this pull request Sep 21, 2025
…etgraph#849)

The function 'zip' was introduced in petgraph#747 as a part of adding `no_std`
support. However, there is already such a function in `core::iter`. The
MSRV stated in the description of petgraph#747 was 1.64 at minimum, but the
function in `core` is stable since Rust 1.59. Thus, it is an unnecessary
duplication and can be removed without consequences.

<!--
  -- Thanks for contributing to `petgraph`! 
  --
-- We require PR titles to follow the Conventional Commits
specification,
-- https://www.conventionalcommits.org/en/v1.0.0/. This helps us
generate
  -- changelogs and follow semantic versioning.
  --
  -- Start the PR title with one of the following:
  --  * `feat:` for new features
  --  * `fix:` for bug fixes
  --  * `refactor:` for code refactors
  --  * `docs:` for documentation changes
  --  * `test:` for test changes
  --  * `perf:` for performance improvements
  --  * `revert:` for reverting changes
  --  * `ci:` for CI/CD changes
-- * `chore:` for changes that don't fit in any of the above categories
  -- The last two categories will not be included in the changelog.
  --
-- If your PR includes a breaking change, please add a `!` after the
type
-- and include a `BREAKING CHANGE:` line in the body of the PR
describing
  -- the necessary changes for users to update their code.
  --
  -->

Co-authored-by: cactusdualcore <cactusdualcore@noreply.codeberg.org>
starovoid pushed a commit to RaoulLuque/petgraph that referenced this pull request Sep 23, 2025
This was discussed in an earlier PR and removes `util.rs` and the `enumerate` function in that file.

Refs: petgraph#849
github-merge-queue bot pushed a commit that referenced this pull request Sep 30, 2025
## 🤖 New release

* `petgraph`: 0.8.2 -> 0.8.3 (✓ API compatible changes)

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

##
[0.8.3](https://github.com/petgraph/petgraph/compare/petgraph@v0.8.2...petgraph@v0.8.3)
- 2025-09-28

### Bug Fixes

- Infinite `subgraph_isomorphisms_iter` for empty isomorphisms
([#780](#780))
- Algos don't work on `UndirectedAdaptor`
([#870](#870))
([#871](#871))
- use a queue for SPFA
([#893](#893))
- `StableGraph::reverse` breaks free lists
([#890](#890))

### Documentation

- Fix examples link in README and unify typesetting of one word
([#823](#823))
- Add link to multigraph definition to isomorphism algos
([#824](#824))
- Fix auxiliary space (and time) complexity of bron-kerbosch
([#825](#825))
- Fix Typo in Operator Module Documentation
([#831](#831))
- Sync the crate feature flags in the README and docs
([#832](#832))
- Remove all \[Generic\] tags from algo docstrings
([#835](#835))
- Fix typos in comments
([#836](#836))
- Revamp CONTRIBUTING.md
([#833](#833))
- Update `GraphMap` link in README
([#857](#857))
- Add doc comment for `Dot::with_attr_getters`
([#850](#850))
- Specify iteration order for neighbors and edges and their variants
([#790](#790))
- Collection of Doc fixes
([#856](#856))

### New Features

- Add `into_nodes_edges_iters` to `StableGraph`
([#841](#841))
- Add methods to reserve & shrink `StableGraph` capacity
([#846](#846))
- Add Dinic's Maximum Flow Algorithm
([#739](#739))
- make Csr::from_sorted_edges generic over edge type and properly
increase edge_count in Csr::from_sorted_edges
([#861](#861))
- Add `map_owned` and `filter_map_owned` for `Graph` and `StableGraph`
([#863](#863))
- Add dijkstra::with_dynamic_goal
([#855](#855))
- Fix self-loop bug in all_simple_paths and enable multiple targets
([#865](#865))
- mark petgraph::dot::Dot::graph_fmt as public
([#866](#866))
- Add bidirectional Dijkstra algorithm
([#782](#782))

### Performance

- Make A* tie break on lower h-values
([#882](#882))

### Refactor

- add examples for scc algorithms and reorganize into dedicated module
([#830](#830))
- Remove unnecessary trait bounds from impls/methods
([#828](#828))
- replace uses of 'crate::util::zip' with 'core::iter::zip'
([#849](#849))
- Fix clippy (and other) lints
([#851](#851))
- Cleanup repo ([#854](#854))
- replace crate::util::enumerate with Iterator::enumerate
([#881](#881))

### Testing

- Add dependency list for 'quickcheck' feature
([#822](#822))
- Fix feature cfg capitalization in doctest
([#852](#852))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Egor Starovoitov <52821033+starovoid@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-crate Area: Petgraph crate functionality C-refactor Category: PR/issue with specific code/suggestions for refactoring S-waiting-on-review Status: Awaiting review from the assignee but also other interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants