Trait vasi::VirtualAddressSpaceIndependent
source · pub unsafe trait VirtualAddressSpaceIndependent {
const IGNORE: () = ();
}
Expand description
A type implementing this trait guarantees that accessing instances of that type outside of their original virtual address space does not violate Rust’s safety requirements.
This is mostly equivalent to them being self-contained: not referring to
memory outside of the range [&self, &self + std::mem::sizeof<T>()]
.
However, they may reference memory outside of that range if they somehow
ensure that they only do so from inside the virtual address space where it
is valid to do so.
Types implementing this trait can definitely not contain references. If they contain pointers, the type is responsible for ensuring those pointers aren’t dereferenced outside a virtual address space where they are valid.
Relative pointers, e.g. as implemented in rkyv, are acceptable as long as they point within the boundaries of the enclosing type.
The type must also be FFI-safe; e.g. have a stable layout (e.g. [repr(C)]
),
to help ensure that different processes accessing data of a given type
actually agree on its layout. Note though that is necessary, but not
sufficient, to ensure they agree on the layout; e.g. things can still go
wrong if processes use different versions of the type. (TODO: maybe split
this property into a separate trait).
§Safety
The type must actually be self-contained, as above.