pub struct ShmMap { /* private fields */ }Expand description
A typed map of shared-memory variable names to their resolved pointers.
_context keeps the underlying Shmem mapping alive for as long as any
ShmMap clone exists. The raw pointers in pointers are only valid while
that mapping is mapped into this process’s address space, so the map
itself must own a reference to it.
Implementations§
Source§impl ShmMap
impl ShmMap
Sourcepub fn new(pointers: HashMap<String, ShmPtr>) -> Self
pub fn new(pointers: HashMap<String, ShmPtr>) -> Self
Build an ShmMap with no anchored context. Only safe when the caller
guarantees that the pointers’ backing memory outlives every ShmMap
clone (e.g. pointers into a static buffer, or in unit tests).
Prefer with_context for anything sourced from ShmContext::resolve.
Sourcepub fn with_context(
pointers: HashMap<String, ShmPtr>,
context: Arc<ShmContext>,
) -> Self
pub fn with_context( pointers: HashMap<String, ShmPtr>, context: Arc<ShmContext>, ) -> Self
Build an ShmMap that anchors its lifetime to context. The Arc
keeps the Shmem mapping alive even if the original owner (e.g.
IpcClient::shm_context) replaces or drops its reference.
Sourcepub fn data_type(&self, name: &str) -> Option<&str>
pub fn data_type(&self, name: &str) -> Option<&str>
The data type the server declared for name, when this map was built
from an ShmContext. None for a context-less map, or an unknown name.
get/read/write are
untyped: nothing checks that T matches the variable, and a too-wide
write silently corrupts whatever the server allocated next. Check this
first when the type comes from config rather than a compile-time constant.
Sourcepub unsafe fn read<T: Copy>(&self, name: &str) -> Option<T>
pub unsafe fn read<T: Copy>(&self, name: &str) -> Option<T>
Read a value from shared memory.
§Safety
Caller must ensure T matches the type of data at the pointer.