Crates.io | uvector |
lib.rs | uvector |
version | 0.3.0 |
source | src |
created_at | 2017-12-22 22:01:44.23948 |
updated_at | 2018-12-07 20:54:35.217932 |
description | access two slices as a single continuous vector |
homepage | |
repository | https://gitlab.com/shaydo/uvector |
max_upload_size | |
id | 44080 |
size | 10,717 |
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.
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);
}