Macro for ensuring type does not contain pointers

Im dealing with some shared memory, and wondering if theres a way i could somewhat to repr(c)
ensure that a struct and all its fields don't contain any pointers.

A type not containing physical pointers is not enough to be safe to share using shared memory. It also has to not reference any process-local state (eg contain a token asserting that a C library has initialized all its global variables) and be Sync. And in addition if the peer you share memory with is not guaranteed to be well behaving, you have to make sure that any possible byte sequence is valid (aka the type is a POD/plain old data). You probably want an unsafe to implement trait that asserts the type is safe to be used with shared memory together with a derive macro that handles known safe cases. For example how https://docs.rs/zerocopy/latest/zerocopy/ does this.

1 Like

Thank you for the provided resource!
Luckly i don't have to worry about any C library tokens and the like; its simply moving data back and forth consumer / producer style.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.