Do atomics need to be initialized in a specific way or can they just be transmuted from their inner type? EDIT: yes
For example, is it okay to transmute a Vec<u64> to a Vec<AtomicU64>? EDIT: NO is the answer to this!
In my actual use case there is also the question of how that will interact with having that memory actually mem mapped:
use memmap2::MmapOptions;
use std::sync::atomic::AtomicU64;
use std::io::Write;
use std::fs::File;
let file = File::open("some_file.saved")?;
let mmap = unsafe { MmapOptions::new().map(&file)? };
let (prefix, shorts, suffix) = mmap.align_to_mut::<AtomicU64>();
assert!(prefix.is_empty() && suffix.is_empty());
let useful: &mut [AtomicU64] = shorts;
Is the above code correct if I only use the useful after this to make atomic changes?
As far as I know, atomics are only different in the instructions that are used to change/read them. I just want to make sure I am not doing something stupid.
If you can transmute safely between those two types, why isn't there just a From impl or convert method that would compile as a no-op? And if there is such a method, why does it matter whether it can be transmuted?
Strictly speaking transmuting them still is UB as DST ref memory layout is unspecified. You can use std::slice::from_raw_parts_mut() to reconstruct it.