2 releases

0.1.1 Nov 2, 2021
0.1.0 Nov 2, 2021

#2895 in Rust patterns

Download history 2/week @ 2024-07-22 16/week @ 2024-07-29 14/week @ 2024-08-05 5/week @ 2024-08-26 24/week @ 2024-09-02 47/week @ 2024-09-09 34/week @ 2024-09-16 63/week @ 2024-09-23 53/week @ 2024-09-30 15/week @ 2024-10-07 22/week @ 2024-10-14 15/week @ 2024-10-21 29/week @ 2024-10-28 50/week @ 2024-11-04

117 downloads per month

Apache-2.0

9KB
135 lines

sub-array

Crates.io API

Allows to extract a sub-array out of an array

Example

Getting a sub array:

use sub_array::SubArray;

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

// Get a sub-array starting at offset 1
let sub: &[u8; 3] = arr.sub_array_ref(1);
assert_eq!(sub, &[2, 3, 4]);

Initializing an [u8;10] array with (u16, u32, u32):

use sub_array::SubArray;

let foo: u16 = 42;
let bar: u32 = 0x1234;
let baz: u32 = 0x5678;

let mut arr = [0_u8; 10];
*arr.sub_array_mut::<2>(0) = foo.to_be_bytes();
*arr.sub_array_mut::<4>(2) = bar.to_be_bytes();
*arr.sub_array_mut::<4>(6) = baz.to_be_bytes();

assert_eq!(
    arr,
    [
        0, 42, // foo
        0x0, 0x0, 0x12, 0x34, // bar
        0x0, 0x0, 0x56, 0x78, // baz
    ]
);

License

Licensed under Apache License, Version 2.0 (LICENSE or https://www.apache.org/licenses/LICENSE-2.0).

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.

No runtime deps