I'd like to wrap a set of plain types acquired from the shared memory, via a trait bound
Plain, but I find it hard to do this.
To clarify, say a type
T is "plain" if:
- it contains no pointers nor references;
- it has no destructor, i.e.
- it contains no
&Tcan be safely transmuted from a
&[u8], where the
&[u8]has the length of
T's size and is properly aligned to
T's internal padding should be guaranteed to be zero;
&mut Tcan be safely transmuted from a zero-filled
&mut [u8], where the length and alignment of
&mut [u8]takes after 5.
Generally, such a plain type
T will be processed as following:
- create a page of shared memory, and allocate as layout of
Tin the page;
- fill the allocated bytes zero, and transmute such
- write arbitrary valid value
Tinto the mutable slice
&mut Tand freeze it (i.e. no longer mutable);
- another process open this shared page, and find the corresponding location of
&[u8](By a inter-process communication, the new process doesn't know the actual type inside, but knows only the offset from the page and the length of bytes);
- it transmutes the
&Tand read its value.
EDIT: it is considered as a specialization of a general type. For
T that is not "plain", we serialize
T to and deserialize
T from a
[u8] instead of transmuting, which means that the shared memory layer must be type-erased.