Crate dont_panic_slice [] [src]

Non-panicking drop-in replacement for slices. Instead of panic it causes link time error if bounds are not checked. (Not fully drop-in replacement yet. Some features are missing.)

Example

#[macro_use]
extern crate dont_panic_slice;

use dont_panic_slice::DPSlice;

fn main() {
    let arr = [0, 1, 2, 3];
    let dps = <&DPSlice<_>>::from(&arr as &[_]);
    assert_eq!(dps[0], 0);
    assert_eq!(dps[3], 3);
    // This would not compile (instead of run time panicking)
    assert_eq!(dps[42], 42);
}

You must compile it with --release. If you don't want to slow down debug builds, you can use --features=panic to switch to normal panicking behaviour.

Structs

DPSlice