Expand description
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.
§Example
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 (do not forget to #[macro_use]
):
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]);
Macros§
- stream
- Convenient helper to use easily the custom streaming iterator.
Traits§
- Slice
Tools - A trait to extend slices and
Vec
s with streaming iterators. - Streamer
Mut - A trait to implement streaming iterators that can return mutable reference to oneself.