Crate map_in_place [] [src]

Reuse allocations when converting the elements of a vector, boxed slice or box to a compatible type.

The *_in_place() methods will panic if the types are not compatible, while the others will fall back to iterating and collecting.

I might add methods to the traits without a default impl or a major version bump; implement them for other types at your own risk. I might also change the panic messages.

Examples:

extern crate map_in_place;
use map_in_place::MapVecInPlace;
fn main() {
    let v = vec![8_u32,29,14,5];
    let v = v.filter_map(|n| if n < 10 {Some( (n as u8+b'0') as char)}
                             else      {None}
                        );// happens in place
    assert_eq!(&v, &['8','5']);
    let v = v.map(|c| c as u8);// falls back to iterators
    assert_eq!(&v[..], &b"85"[..]);
}

Traits

MapBoxInPlace
MapSliceInPlace
MapVecInPlace