uvector

Crates.iouvector
lib.rsuvector
version0.3.0
sourcesrc
created_at2017-12-22 22:01:44.23948
updated_at2018-12-07 20:54:35.217932
descriptionaccess two slices as a single continuous vector
homepage
repositoryhttps://gitlab.com/shaydo/uvector
max_upload_size
id44080
size10,717
Pavel Shaydo (trinitum)

documentation

README

A Rust library providing read-only array type allowing access two slices as a single continuous vector. Can be used for example to conveniently access parts of VecDeque.

Example

use std::collections::VecDeque;
use uvector::UVec;

// Return sum of the first 3 numbers in VecDeque
fn head3_sum(vd: &VecDeque<i32>) -> i32 {
    let uv = UVec::new(vd.as_slices());
    uv.range(0, 3).iter().fold(0, |sum, x| sum + x)
}

fn main() {
    let mut vd: VecDeque<i32> = VecDeque::new();
    for i in 1..6 {
        vd.push_back(i);
    }
    let s = head3_sum(&vd);
    assert_eq!(s, 6);
}
Commit count: 15

cargo fmt