pub fn write_once<F: FnOnce(&mut[u8])>(size: u64, name: &str, f: F) -> Result<mfd::Memfd, Error> {
    let opts = memfd::MemfdOptions::new().allow_sealing(true).close_on_exec(true);
    let mut h = mfd::SealsHashSet::new();
    h.insert(mfd::FileSeal::SealGrow);
    h.insert(mfd::FileSeal::SealShrink);
    h.insert(mfd::FileSeal::SealSeal);
    h.insert(mfd::FileSeal::SealWrite);

    write_once_custom(size, name, opts, &h, f)
}
/// Creates a shared memory area that can be written once and read many times.
///
/// The memfd is created, memory mapped and the closure can fill in the data.
/// After the data is filled in, the memfd is sealed to be read only.
///
/// # Example
/// ```rust
/// use shmem_ipc::mem::{write_once, read_memfd};
/// // Create a 4 MB memory area
/// let memfd = write_once(1024*1024*4, "write_then_read_test", |x| {
///      // Fill it with data
///      for (i, j) in x.iter_mut().enumerate() { *j = i as u8; }
/// }).unwrap();
///  /* ... send the memfd to another process somehow ... */
/// let map = read_memfd(&memfd).unwrap();
/// // Read the data
/// for (i, j) in map.iter().enumerate() { assert_eq!(i as u8, *j); }
/// ```
Creates a shared memory area that can be written once and read many times.
The memfd is created, memory mapped and the closure can fill in the data.
After the data is filled in, the memfd is sealed to be read only.
Creates a shared memory area that can be written once and read many times . The memfd is created memory mapped and the closure can fill in the data . After the data is filled in the memfd is sealed to be read only .
pub fn write_once<F: FnOnce(&mut[u8])>(size: u64, name: &str, f: F) -> Result<mfd::Memfd, Error> {
    let opts = memfd::MemfdOptions::new().allow_sealing(true).close_on_exec(true);
    let mut h = mfd::SealsHashSet::new();
    h.insert(mfd::FileSeal::SealGrow);
    h.insert(mfd::FileSeal::SealShrink);
    h.insert(mfd::FileSeal::SealSeal);
    h.insert(mfd::FileSeal::SealWrite);
    write_once_custom(size, name, opts, &h, f)
}
pub fn write_once < F : FnOnce ( & mut [ u8 ] ) > ( size : u64 , name : & str , f : F ) -> Result < mfd :: Memfd , Error > { let opts = memfd :: MemfdOptions :: new ( ) . allow_sealing ( true ) . close_on_exec ( true ) ; let mut h = mfd :: SealsHashSet :: new ( ) ; h . insert ( mfd :: FileSeal :: SealGrow ) ; h . insert ( mfd :: FileSeal :: SealShrink ) ; h . insert ( mfd :: FileSeal :: SealSeal ) ; h . insert ( mfd :: FileSeal :: SealWrite ) ; write_once_custom ( size , name , opts , & h , f ) }
Creates a shared memory area that can be written once and read many times.
Creates a shared memory area that can be written once and read many times .
size
u64
name
&str
f
F
size
u64
name
&str
f
F
example
```rust
use shmem_ipc::mem::{write_once, read_memfd};
Create a 4 MB memory area
let memfd = write_once(1024*1024*4, "write_then_read_test", |x| {
Fill it with data
for (i, j) in x.iter_mut().enumerate() { *j = i as u8; }
}).unwrap();
send the memfd to another process somehow
let map = read_memfd(&memfd).unwrap();
Read the data
for (i, j) in map.iter().enumerate() { assert_eq!(i as u8, *j); }
```
` ` ` rust use shmem_ipc :: mem :: { write_once read_memfd } ; Create a 4 MB memory area let memfd = write_once ( 1024 * 1024 * 4 " write_then_read_test " |x| { Fill it with data for ( i j ) in x . iter_mut () . enumerate () { * j = i as u8 ; } } ) . unwrap () ; send the memfd to another process somehow let map = read_memfd ( &memfd ) . unwrap () ; Read the data for ( i j ) in map . iter () . enumerate () { assert_eq! ( i as u8 * j ) ; } ` ` `