#vec #transmute #pod

no-std transvec

A crate to safely transmute Vecs

10 releases

0.3.7 Nov 7, 2021
0.3.6 Aug 21, 2021
0.3.5 Jul 30, 2021
0.2.4 Jul 4, 2021
0.1.0 Jul 3, 2021

#420 in Memory management

40 downloads per month

MIT OR Unlicense

616 lines


transvec is a crate for transmuting Vecs without copying.


Add this to your Cargo.toml:

transvec = "0.3"


use transvec::transmute_vec;
let input: Vec<u8> = vec![1, 2, 3, 4];
let output: Vec<u16, _> = transmute_vec(input).unwrap();


This supports no_std, just disable the default features, and optionally enable allocator_api, which in addition requires atomic pointers. It does require alloc though.


This is nightly because it's blocked on the allocator_api, which is how this crate can get around the aligment issue.

You can however turn off default features, and optionally enable std to make it work on stable, with the only options being transmute_vec_basic and transmute_vec_basic_may_copy.


Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.