fn unsafe_save_vec<T: Copy>(vec: &Vec<T>, schema_hash: u64, mut path: std::path::PathBuf) {
    path.set_extension("rc");
    trace!("[enter] save({:?})", path);
    let mut file = std::fs::File::create(&path)
        .unwrap_or_else(|e| panic!("Unable to create {:?}: {}", path, e));
    if cfg!(target_endian = "big") {
        unreachable!("We assume little endian machines");
    }
    let element_size = std::mem::size_of::<T>();
    let len = vec.len();
    file.write_all(&(schema_hash as u64).to_le_bytes()).unwrap();
    file.write_all(&(element_size as u64).to_le_bytes())
        .unwrap();
    file.write_all(&(len as u64).to_le_bytes()).unwrap();
    let begin_ptr = vec.as_ptr() as *const u8;
    // TODO: Is there a safe and equally fast way of doing this?
    let data = unsafe { std::slice::from_raw_parts(begin_ptr, element_size * len) };
    file.write_all(data).unwrap();
    trace!("[exit] save({:?})", path);
}
/// **Note:** this function is not marked unsafe just so that we could use unsafe blocks
/// to mark precisely where we are performing unsafe operations.
this function is not marked unsafe just so that we could use unsafe blocks
to mark precisely where we are performing unsafe operations.
this function is not marked unsafe just so that we could use unsafe blocks to mark precisely where we are performing unsafe operations .
fn unsafe_save_vec<T: Copy>(vec: &Vec<T>, schema_hash: u64, mut path: std::path::PathBuf) {
    path.set_extension("rc");
    trace!("[enter] save({:?})", path);
    let mut file = std::fs::File::create(&path)
        .unwrap_or_else(|e| panic!("Unable to create {:?}: {}", path, e));
    if cfg!(target_endian = "big") {
        unreachable!("We assume little endian machines");
    }
    let element_size = std::mem::size_of::<T>();
    let len = vec.len();
    file.write_all(&(schema_hash as u64).to_le_bytes()).unwrap();
    file.write_all(&(element_size as u64).to_le_bytes())
        .unwrap();
    file.write_all(&(len as u64).to_le_bytes()).unwrap();
    let begin_ptr = vec.as_ptr() as *const u8;
    // TODO: Is there a safe and equally fast way of doing this?
    let data = unsafe { std::slice::from_raw_parts(begin_ptr, element_size * len) };
    file.write_all(data).unwrap();
    trace!("[exit] save({:?})", path);
}
fn unsafe_save_vec < T : Copy > ( vec : & Vec < T > , schema_hash : u64 , mut path : std :: path :: PathBuf ) { path . set_extension ( " " ) ; trace ! ( " " path ) ; let mut file = std :: fs :: File :: create ( & path ) . unwrap_or_else ( | e | panic ! ( " " path e ) ) ; if cfg ! ( target_endian " " ) { unreachable ! ( " " ) ; } let element_size = std :: mem :: size_of :: < T > ( ) ; let len = vec . len ( ) ; file . write_all ( & ( schema_hash as u64 ) . to_le_bytes ( ) ) . unwrap ( ) ; file . write_all ( & ( element_size as u64 ) . to_le_bytes ( ) ) . unwrap ( ) ; file . write_all ( & ( len as u64 ) . to_le_bytes ( ) ) . unwrap ( ) ; let begin_ptr = vec . as_ptr ( ) as * const u8 ; // TODO: Is there a safe and equally fast way of doing this? let data = unsafe { std :: slice :: from_raw_parts ( begin_ptr , element_size * len ) } ; file . write_all ( data ) . unwrap ( ) ; trace ! ( " " path ) ; }
Note:** this function is not marked unsafe just so that we could use unsafe blocks
to mark precisely where we are performing unsafe operations.
Note : ** this function is not marked unsafe just so that we could use unsafe blocks to mark precisely where we are performing unsafe operations .
vec
&Vec<T>
schema_hash
u64
path
std::path::PathBuf