1 stable release
Uses old Rust 2015
1.0.0 | Jan 2, 2018 |
---|
#66 in #place
3KB
slice_mip – Mutate a slice in place with a map function
This crate provides a convenience utility for replacing the items in a slice with the result of a map function applied to each item.
Example
use slice_mip::MapInPlace;
let mut buf = [1, 2, 3, 4];
buf.map_in_place(|x| x * 2);
assert_eq!(buf, [2, 4, 6, 8]);
Usage
This crate can be used through cargo by
adding it as a dependency in Cargo.toml
:
[dependencies]
slice_mip = "1.0.0"
and importing it in the crate root:
extern crate slice_mip;
The provided slice method can then be used by importing the trait within individual modules:
use slice_mip::MapInPlace;
lib.rs
:
Mutate a slice in place with a map function.
Note that the map result type must be the same as the input type.
Example
use slice_mip::MapInPlace;
let mut buf = [1, 2, 3, 4];
buf.map_in_place(|x| x * 2);
assert_eq!(buf, [2, 4, 6, 8]);