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

fix: be explicit on used generic types and lifetimes #611

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ authors = ["Samuel Tardieu <[email protected]>"]
categories = ["algorithms"]
readme = "README.md"
edition = "2021"
rust-version = "1.77.2"
rust-version = "1.82.0"

[package.metadata.release]
sign-commit = true
Expand Down
2 changes: 1 addition & 1 deletion examples/sliding-puzzle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl Game {
// However, since the successors are the current board with the hole moved one
// position, we need to build a clone of the current board that will be reused in
// this iterator.
fn successors(&self) -> impl Iterator<Item = (Game, u8)> {
fn successors(&self) -> impl Iterator<Item = (Game, u8)> + use<> {
let game = self.clone();
SUCCESSORS[self.hole_idx as usize]
.iter()
Expand Down
2 changes: 1 addition & 1 deletion src/directed/idastar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ where
path.push(node);
match search(path, cost + extra, bound, successors, heuristic, success) {
found_path @ Path::Found(_, _) => return found_path,
Path::Minimum(m) if !min.is_some_and(|n| n < m) => min = Some(m),
Path::Minimum(m) if min.is_none_or(|n| n >= m) => min = Some(m),
_ => (),
}
path.pop();
Expand Down
2 changes: 1 addition & 1 deletion src/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ impl Grid {

/// Return an iterator over the border vertices. The grid must not have
/// a zero width or height.
fn borders(&self) -> impl Iterator<Item = (usize, usize)> {
fn borders(&self) -> impl Iterator<Item = (usize, usize)> + use<> {
let width = self.width;
let height = self.height;
(0..width)
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
//! in this context, you can wrap them into compliant types using the
//! [ordered-float](https://crates.io/crates/ordered-float) crate.
//!
//! The minimum supported Rust version (MSRV) is Rust 1.77.2.
//! The minimum supported Rust version (MSRV) is Rust 1.82.0.
//!
//! [A*]: https://en.wikipedia.org/wiki/A*_search_algorithm
//! [BFS]: https://en.wikipedia.org/wiki/Breadth-first_search
Expand Down
8 changes: 4 additions & 4 deletions src/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ impl<C> Matrix<C> {
&self,
(r, c): (usize, usize),
diagonals: bool,
) -> impl Iterator<Item = (usize, usize)> {
) -> impl Iterator<Item = (usize, usize)> + use<C> {
let (row_range, col_range) = if r < self.rows && c < self.columns {
(
r.saturating_sub(1)..(self.rows).min(r + 2),
Expand Down Expand Up @@ -597,7 +597,7 @@ impl<C> Matrix<C> {
&self,
start: (usize, usize),
direction: (isize, isize),
) -> impl Iterator<Item = (usize, usize)> {
) -> impl Iterator<Item = (usize, usize)> + use<C> {
in_direction(start, direction, (self.rows, self.columns))
}

Expand Down Expand Up @@ -628,14 +628,14 @@ impl<C> Matrix<C> {
since = "4.1.0",
remove = "> 4.x"
)]
pub fn indices(&self) -> impl Iterator<Item = (usize, usize)> {
pub fn indices(&self) -> impl Iterator<Item = (usize, usize)> + use<C> {
self.keys()
}

/// Return an iterator on the Matrix indices, first row first. The values are
/// computed when this method is called and will not change even if new rows are
/// added before the iterator is consumed.
pub fn keys(&self) -> impl Iterator<Item = (usize, usize)> {
pub fn keys(&self) -> impl Iterator<Item = (usize, usize)> + use<C> {
let columns = self.columns;
(0..self.rows).flat_map(move |r| (0..columns).map(move |c| (r, c)))
}
Expand Down
2 changes: 1 addition & 1 deletion tests/pathfinding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod ex1 {
use pathfinding::prelude::*;

#[allow(clippy::trivially_copy_pass_by_ref)]
fn successors(node: &u8) -> impl Iterator<Item = (u8, usize)> {
fn successors(node: &u8) -> impl Iterator<Item = (u8, usize)> + use<> {
lazy_static! {
static ref SUCCESSORS: Vec<Vec<(u8, usize)>> = vec![
vec![(1, 7), (2, 7), (3, 6)],
Expand Down
Loading