unsafe-access
A collection of Rust procedural macros designed to simplify the use of unsafe array indexing while maintaining traditional indexing semantics. These macros are especially beneficial in performance-critical areas where bounds-checking can be explicitly bypassed, assuming prior validation. The key feature is retaining standard array indexing syntax while skipping bounds checks, which can yield significant performance benefits.
Macros
unchecked_indices_ref,unchecked_indices_clone,unchecked_indices_copy. These macros let the user access array elements viaget_uncheckedin a limited scope. This isunsafecode.
use unchecked_indices_copy;
let array = ;
let indices = ;
let copied_array: = unchecked_indices_copy! ;
unsafe_access_fnAn attribute macro that transforms standard array indexing within a function into unsafe, unchecked array indexing. This macro ensures that all indexing operations inside the function are converted to useget_unchecked. This example can be found inexamples/matrices.rs:
use unsafe_access_fn;
const MATRIX_SIZE: usize = 100;
const QUERY_SIZE: usize = 5;
unsafe
To run the example, execute:
Benchmarks
For a simple benchmark using random accesses, see benches/access.rs, or via