4 releases (2 breaking)

Uses old Rust 2015

0.3.0 Dec 7, 2018
0.2.0 Dec 29, 2017
0.1.1 Dec 22, 2017
0.1.0 Dec 22, 2017

#2486 in Data structures

MIT license

9KB
151 lines

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);
}

lib.rs:

Allows access two read-only slices as a single vector.

No runtime deps