Skip to content

Commit

Permalink
fix: be explicit on used generic types and lifetimes
Browse files Browse the repository at this point in the history
  • Loading branch information
samueltardieu committed Nov 23, 2024
1 parent a791525 commit 5ede02a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
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/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
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

0 comments on commit 5ede02a

Please sign in to comment.