Skip to content

access two slices as a single continuous vector

License

Notifications You must be signed in to change notification settings

trinitum/uvector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

access two slices as a single continuous vector

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages