[][src]Macro multindex::multiget

macro_rules! multiget {
    ( $slice:expr; $($index:expr),* $(,)? ) => { ... };
}

For immutable indexing of slices with multiple indices/ranges.

This macro returns None if the indices/ranges are out of bounds for the passed slice, returns Some if they are in bounds.

Shared docs

The indexing macros share a lot in common, because of that you can look here for additional documentation.

Example

use multindex::multiget;

let arr = [3u8, 5, 8, 13, 21, 34];

assert_eq!(multiget!(arr; 0, 2, 4), Some((&3, &8, &21)));

// The `2..=4` here returns a `&[u8; 3]`, since it's a bounded range.
assert_eq!(multiget!(arr; 0, 2..=4), Some((&3, &[8, 13, 21])));

// The `..` here returns a `&[u8]`, since it's a trailing unbounded range
assert_eq!(multiget!(arr; ..2, ..), Some((&[3, 5], &[8, 13, 21, 34][..])));

assert_eq!(multiget!(arr; 0, 1, 10), None);

assert_eq!(multiget!(arr; 0..10), None);