check-bounds-safety

Enforce type-safe index and length wrappers for Rust bounds checking.

477|32|Updated Feb 23, 2022
One-click install
npx skills add https://github.com/r3bl-org/r3bl-open-core --skill check-bounds-safety
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: check-bounds-safety
Source: https://github.com/r3bl-org/r3bl-open-core/tree/main/.claude/skills/check-bounds-safety
Command: npx skills add https://github.com/r3bl-org/r3bl-open-core --skill check-bounds-safety

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill enforces type-safe bounds handling by replacing ambiguous raw indices with explicit Index/Length wrappers, reducing off-by-one errors and cross-type comparisons in Rust UI code.

Core Features & Use Cases

  • Type-safe index and length wrappers (idx(), len()) to prevent mixed-type comparisons and off-by-one errors.
  • Dedicated bounds-check traits: ArrayBoundsCheck, CursorBoundsCheck, ViewportBoundsCheck, RangeBoundsExt, and RangeConvertExt.
  • Use cases across text editors, rendering pipelines, and range processing where indices and boundaries matter, including cursor positioning and viewport visibility checks.
  • Encourages using TermRowDelta/TermColDelta for safe ANSI cursor movement.

Quick Start

Import the bound-checking primitives (idx, len, ArrayBoundsCheck, CursorBoundsCheck, ViewportBoundsCheck). Replace raw indices with Index/Length types and perform the appropriate checks before access or rendering. Example: let i = idx(10); let l = len(12); if i.overflows(l) { /* handle out of bounds */ } let pos = idx(5); l.check_cursor_position_bounds(pos) // validate cursor position; let visible = i.check_viewport_bounds(start, viewport_size) // determine visibility.

Frequently Asked Questions about check-bounds-safety

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent off-by-one errors and unsafe index handling in Rust?

Type-safe bounds handling prevents off-by-one errors in Rust by replacing raw indices with explicit Index and Length wrappers, ensuring invalid array access is caught before compilation or execution.

What is the best way to enforce type-safe cursor positioning in a Rust text editor?

Type-safe cursor positioning uses the CursorBoundsCheck trait to validate cursor locations against Length boundaries, preventing cross-type comparisons and ensuring the cursor remains within valid text ranges.

How do I check viewport visibility for UI rendering in Rust without raw index comparisons?

Viewport visibility checks use the ViewportBoundsCheck trait on Index types to safely determine if an element is visible within a given start position and viewport size, eliminating unsafe raw index math.

Can I use type-safe wrappers for ANSI cursor movement in Rust rendering pipelines?

Yes, type-safe wrappers like TermRowDelta and TermColDelta enable safe ANSI cursor movement by enforcing bounds validation through dedicated traits before applying rendering pipeline changes.

How do I convert and validate range boundaries for array processing in Rust?

Range processing in Rust uses RangeBoundsExt and RangeConvertExt traits to validate and convert range boundaries against type-safe Index and Length wrappers, preventing overflow and out-of-bounds access during array operations.