#chunks #owned #iterator #traits #vec #panic #vec-i32

nightly owned_chunks

a collection of traits and iterators to get owned chunks from collections

1 unstable release

0.1.1 Jan 12, 2022
0.1.0 Nov 21, 2021

#2303 in Data structures

Download history 5/week @ 2024-01-29 25/week @ 2024-02-05 10/week @ 2024-02-12 39/week @ 2024-02-19 38/week @ 2024-02-26 48/week @ 2024-03-04

139 downloads per month

MIT license

27KB
425 lines

owned_chunks

A collection of iterators and traits that allow you to get owned chunks from collections (currently Vec and array)

Example

use owned_chunks::OwnedChunks;

fn take_ownership(v: Vec<i32>) {
    // implementation
}

for (ix, chunk) in vec![vec![1, 2], vec![3, 4], vec![5, 6]].owned_chunks(2).enumerate() {
    match ix {
        0 => assert_eq!(&[vec![1, 2], vec![3, 4]], chunk.as_slice()),
        1 => assert_eq!(&[vec![5, 6]], chunk.as_slice()),
        _ => panic!("no more chunks expected"),
    }

    for vec in chunk {
        take_ownership(vec);
    }
}

License: GPL-2.0-or-later


lib.rs:

A collection of iterators and traits that allow you to get owned chunks from collections (currently Vec and array)

Example

use owned_chunks::OwnedChunks;

fn take_ownership(v: Vec<i32>) {
    // implementation
}

for (ix, chunk) in vec![vec![1, 2], vec![3, 4], vec![5, 6]].owned_chunks(2).enumerate() {
    match ix {
        0 => assert_eq!(&[vec![1, 2], vec![3, 4]], chunk.as_slice()),
        1 => assert_eq!(&[vec![5, 6]], chunk.as_slice()),
        _ => panic!("no more chunks expected"),
    }

    for vec in chunk {
        take_ownership(vec);
    }
}

No runtime deps