lexical_parse_float/
index.rs

1//! Wrapper around indexing for opt-in, additional safety.
2//!
3//! This is used very sparing in parsers, only when code can trivially
4//! be shown to be safe, since parsers are tricky to validate.
5
6#![cfg_attr(not(feature = "power-of-two"), allow(unused_macros))]
7#![doc(hidden)]
8
9/// Index a buffer, without bounds checking.
10#[cfg(not(feature = "safe"))]
11macro_rules! index_unchecked {
12    ($x:ident[$i:expr]) => {
13        *$x.get_unchecked($i)
14    };
15}
16
17/// Index a buffer and get a mutable reference, without bounds checking.
18#[cfg(not(feature = "safe"))]
19#[allow(unknown_lints, unused_macro_rules)]
20macro_rules! index_unchecked_mut {
21    ($x:ident[$i:expr]) => {
22        *$x.get_unchecked_mut($i)
23    };
24}
25
26/// Index a buffer, with bounds checking.
27#[cfg(feature = "safe")]
28macro_rules! index_unchecked {
29    ($x:ident[$i:expr]) => {
30        $x[$i]
31    };
32}
33
34/// Index a buffer and get a mutable reference, with bounds checking.
35#[cfg(feature = "safe")]
36#[allow(unknown_lints, unused_macro_rules)]
37macro_rules! index_unchecked_mut {
38    ($x:ident[$i:expr]) => {
39        $x[$i]
40    };
41}