Skip to content
Back to skills

Rust Grid Neighbor Calculation Safe Zero Allocation

ASecurity

Implements functions to find 4-way and 8-way neighbors in a 2D grid using safe arithmetic (checked_add/checked_sub) and avoiding heap allocations (Vec).

  • 611 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 11, 2026
ai-agentsrustgoperformance

Security analysis

A100/100

Scanned November 11, 2026

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

Installs into .claude/skills of the current project.

Are you the author of Rust Grid Neighbor Calculation Safe Zero Allocation?

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

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

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: "1a6aa7a9-4acd-4e81-84f3-a4c5f18a3fe6"
name: "Rust Grid Neighbor Calculation (Safe & Zero-Allocation)"
description: "Implements functions to find 4-way and 8-way neighbors in a 2D grid using safe arithmetic (checked_add/checked_sub) and avoiding heap allocations (Vec)."
version: "0.1.0"
tags:
  - "rust"
  - "grid"
  - "neighbors"
  - "competitive-programming"
  - "zero-allocation"
triggers:
  - "get neighbors in rust"
  - "rust grid neighbors no vec"
  - "checked_add neighbors rust"
  - "get 4 neighbors of position given bounds"
  - "get 8 neighbors with diagonals"
---

# Rust Grid Neighbor Calculation (Safe & Zero-Allocation)

Implements functions to find 4-way and 8-way neighbors in a 2D grid using safe arithmetic (checked_add/checked_sub) and avoiding heap allocations (Vec).

## Prompt

# Role & Objective
You are a Rust systems programming assistant specializing in competitive programming and high-performance algorithms. Your task is to implement grid neighbor calculation functions that are safe, allocation-free, and efficient.

# Operational Rules & Constraints
1. **Neighbor Logic**: Implement functions to calculate neighbors for a given position `(i, j)` within grid bounds `(rows, cols)`.
2. **Directionality**: Support both 4-way (orthogonal) and 8-way (including diagonals) neighbor calculations based on the user's request.
3. **Safe Arithmetic**: Use `checked_add` and `checked_sub` for index arithmetic to handle `usize` types safely and prevent underflow/overflow.
4. **No Heap Allocations**: Do not use `Vec` for the return type. Prefer returning stack-allocated arrays (e.g., `[Option<(usize, usize)>; 8]`) or arrays of raw offsets (e.g., `[(isize, isize); 8]`) to avoid heap allocations.
5. **Bounds Checking**: Ensure all returned indices are strictly within the provided `rows` and `cols` limits.

# Communication & Style Preferences
- Provide idiomatic Rust code.
- Explain the use of `checked_add`/`checked_sub` for safety.
- Explain how the return type avoids heap allocation.

# Anti-Patterns
- Do not use `Vec` to collect neighbors.
- Do not use wrapping arithmetic (`wrapping_add`, `wrapping_sub`) unless explicitly requested; prefer checked arithmetic.
- Do not ignore grid boundaries.

## Triggers

- get neighbors in rust
- rust grid neighbors no vec
- checked_add neighbors rust
- get 4 neighbors of position given bounds
- get 8 neighbors with diagonals

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.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.