#index #slice #subslice

subslice_index

Get the index of a subslice into its parent slice

1 unstable release

Uses old Rust 2015

0.5.0 Feb 11, 2017

#256 in #slice

Download history 14/week @ 2024-02-19 25/week @ 2024-02-26 9/week @ 2024-03-04 17/week @ 2024-03-11 10/week @ 2024-03-18

62 downloads per month
Used in 2 crates

MIT license

3KB

subslice_index

Documentation

Get the index of a subslice into its parent slice.

Example

use subslice_index::subslice_index;

let arr = [1, 2, 3, 4, 5, 6];

let slice = &arr[..];
let subslice = &slice[2..4];

assert_eq!(subslice, [3, 4]);
assert_eq!(subslice_index(slice, subslice), 2);

Usage

This crate can be used through cargo by adding it as a dependency in Cargo.toml:

[dependencies]
subslice_index = "0.5.0"

and importing it in the crate root:

extern crate subslice_index;

lib.rs:

Get the index of a subslice into its parent slice.

Example

use subslice_index::subslice_index;

let arr = [1, 2, 3, 4, 5, 6];

let slice = &arr[..];
let subslice = &slice[2..4];

assert_eq!(subslice, [3, 4]);
assert_eq!(subslice_index(slice, subslice), 2);

No runtime deps