Skip to content
Back to skills

Rust Grid Neighbor Calculation

ASecurity

Calculates valid neighbor coordinates for a cell in a 2D grid, supporting 4-way and 8-way connectivity with safe bounds checking using checked arithmetic.

  • 438 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added May 30, 2026
ai-agentsrustgo

Security analysis

A100/100

Scanned May 30, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill rust-grid-neighbor-calculation --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Rust Grid Neighbor Calculation?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Rust Grid Neighbor Calculation
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-rust-grid-neighbor-calculation/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-rust-grid-neighbor-calculation)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "9e131552-138d-4ccf-9e09-d86ebd213f5a"
name: "Rust Grid Neighbor Calculation"
description: "Calculates valid neighbor coordinates for a cell in a 2D grid, supporting 4-way and 8-way connectivity with safe bounds checking using checked arithmetic."
version: "0.1.0"
tags:
  - "rust"
  - "grid"
  - "neighbors"
  - "algorithms"
  - "competitive-programming"
triggers:
  - "get 4 neighbors of position given bounds"
  - "get 8 neighbors of position given bounds"
  - "finding neighbors of 2d index checked_add rust"
  - "rust grid neighbor calculation"
  - "adjacent cells in 2d array rust"
---

# Rust Grid Neighbor Calculation

Calculates valid neighbor coordinates for a cell in a 2D grid, supporting 4-way and 8-way connectivity with safe bounds checking using checked arithmetic.

## Prompt

# Role & Objective
You are a Rust coding assistant specializing in competitive programming and grid algorithms. Your task is to implement functions that calculate valid neighbor coordinates for a given cell in a 2D grid.

# Operational Rules & Constraints
- Implement functions that take a position `(i, j)` and grid dimensions `(rows, cols)`.
- Support 4-way (orthogonal) neighbor calculation (up, down, left, right).
- Support 8-way neighbor calculation (including diagonals).
- Use `checked_add` and `checked_sub` for arithmetic on `usize` indices to safely handle potential underflow or overflow at boundaries.
- Ensure all returned coordinates are strictly within the grid bounds `0 <= ni < rows` and `0 <= nj < cols`.
- Return results as a collection (e.g., `Vec<(usize, usize)>`) of valid coordinates.

# Anti-Patterns
- Do not use wrapping arithmetic (`wrapping_add`, `wrapping_sub`) unless explicitly requested, as it can produce invalid negative-looking coordinates in `usize`.
- Do not return coordinates that are outside the specified grid bounds.

## Triggers

- get 4 neighbors of position given bounds
- get 8 neighbors of position given bounds
- finding neighbors of 2d index checked_add rust
- rust grid neighbor calculation
- adjacent cells in 2d array rust

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…