While this might be correct for all usecases, this is not safe for 100% of host target scenarios. Quoting the docs:
The size of this primitive is how many bytes it takes to reference any location in memory. For example, on a 32 bit target, this is 4 bytes and on a 64 bit target, this is 8 bytes.
What it is is undefined. That's why there's TryFrom which the compiler should remove if the target's error is infallible.
usize::try_from(region.len()).expect("usize primitive too small or something like that"),
What it is is undefined. That's why there's
TryFrom
which the compiler should remove if the target's error is infallible._Originally posted by @epilys in https://github.com/rust-vmm/vm-memory/pull/235#discussion_r1211417479_