Skip to main content

vec_as_bytes

Function vec_as_bytes 

Source
pub fn vec_as_bytes<T: Pod>(data: Vec<T>) -> Bytes
Expand description

Convert an owned Vec of a bytemuck::Pod type into an owned buffer of bytes.

Unlike to_bytes, this does not convert byte order: the returned bytes are in the host’s native byte order, which only matches to_bytes’s little-endian output on a little-endian host.

§Examples

use mzdata_bindata::vec_as_bytes;

let values: Vec<f32> = vec![1.0, 2.0, 3.0];
let bytes = vec_as_bytes(values);
assert_eq!(bytes.len(), 3 * 4);