[][src]Crate typed_shmem

typed_shmem

Provides the ShMem and ShMemCfg types for creating a shared memory region.

In order of a type T to be compatible with the shared memory implementation here present it must be T: zerocopy::AsBytes + zerocopy::FromBytes + Default.

Since there is no synchronization when reading/mutating the shared data, the programmer has to be responsible of how to do so in order to not corrupt said data.

Example

Owner process

use typed_shmem as sh;
use typed_shmem::error::ShMemErr;

fn main() -> Result<(), ShMemErr> {
    let mut mem = sh::ShMemCfg::<u32>::default()
         .set_owner()
         .on_file("test_program")
         .build()?;

    // ShMem<T> implements Deref and DerefMut.
    *mem = 10; //Write.
    assert_eq!(*mem, 10); //Read.

    loop {} //Used to keep the process alive, thus the allocated shared memory too.
     
    Ok(())
}

Any other process

use typed_shmem as sh;
use typed_shmem::error::ShMemErr;

fn main() -> Result<(), ShMemErr> {
    let mut mem = sh::ShMemCfg::<u32>::default()
             .set_file("test_program")
             .build()?;

    assert_eq!(*mem, 10); //Read.

    Ok(())
}

Panics

If the platform on which this crate is compiled does not comply with cfg(unix) nor with cfg(windows), the program will panic.

Modules

error

Structs

ShMem

Contains the platform-specific implementation details for shared memory. The memory itself it is accessed through the Deref and DerefMut traits.

ShMemCfg

Configures and initilizes a shared memory region. By default, the segment name is ramdomly created and this instance is not the owner of the memory object.