Function transvec::transmute_vec_basic[][src]

pub fn transmute_vec_basic<I: Pod, O: Pod>(
    input: Vec<I>
) -> Result<Vec<O>, (Vec<I>, TransmuteError)>
Expand description

If alignment is the same this function is preferred over transmute_vec.

Errors

  1. The length of the vector wouldn’t fit the type.
let input: Vec<u8> = vec![1, 2, 3];
let output: Vec<u16, _> = transmute_vec_basic(input).unwrap();
  1. The capacity can’t be converted to units of the output type.
let input: Vec<u8> = Vec::with_capacity(3);
let output: Vec<u16, _> = transmute_vec_basic(input).unwrap();

Length, then capacity will be returned.

ZSTs

  1. Anything -> ZST
    • Keeps length, deallocates data.
  2. ZST -> Non ZST
    • New Vec from previous allocator.
  3. Just don’t do this.

Panics

Panics if the alignment is not the same. (This may be turned into a compile time error in the future, when possible without using nightly features).

Otherwise this acts exactly the same as transmute_vec.