Crates.io | shm-fd |
lib.rs | shm-fd |
version | 0.5.0 |
source | src |
created_at | 2022-04-08 23:08:41.786521 |
updated_at | 2024-01-20 19:30:26.595882 |
description | Like systemfd/listenfd but with a shared-memory file descriptor |
homepage | |
repository | https://github.com/HeroicKatora/shmfd |
max_upload_size | |
id | 564460 |
size | 27,025 |
This crate is part of a group that enables using shared-memory files conveniently for persisting state across program restarts. Programs can access this file via language and runtime independent means from the environment. This crate contains a simple binary to configure such an environment, and a library to consume it.
use shm_fd::SharedFd;
// Trust the environment..
let fd = unsafe { SharedFd::from_env() }?;
let memfile = fd.into_file()?;
// Example: utilize the shared memory via memmap2 crate
use memmap2::MmapMut;
let mapping = unsafe { MmapMut::map_mut(file.as_raw_fd()) }?;
let memory = &mut mapping[..];