Crates.io | slicetools |
lib.rs | slicetools |
version | 0.3.0 |
source | src |
created_at | 2018-03-07 20:52:39.842458 |
updated_at | 2018-03-11 20:31:38.482455 |
description | Add extra iterators to slices. |
homepage | |
repository | https://gitlab.com/Boiethios/slicetools/ |
max_upload_size | |
id | 54409 |
size | 29,576 |
This crate aims to provide various tools for slices.
This crate use its own streaming iterator
due to the lack of generic associated type in the language:
you therefore cannot use those iterators with the for
control flow.
Use the while let
control flow, or the macro helper, as you can see below.
Cargo.toml:
[dependencies]
slicetools = "0.2.*"
main.rs:
extern crate slicetools;
use slicetools::*;
let mut v = vec![1, 2, 3, 4];
{
let mut it = v.pairs_mut();
while let Some((a, b)) = it.next() {
if *b > *a {
*a += 1;
}
}
}
assert_eq!(v, &[4, 4, 4, 4]);
Or, with the helper macro:
#[macro_use] extern crate slicetools;
use slicetools::*;
let mut v = vec![1, 2, 3, 4];
stream!( v.pairs_mut() => (a, b) in {
if *b > *a {
*a += 1;
}
});
assert_eq!(v, &[4, 4, 4, 4]);
Use own streaming iterator instead of regular iterator that was unsafe (allowed multiple mutable borrowing on the same item).
Add a new streamer for doing a cartesian product between two slices.