[][src]Crate typed_shmem

typed_shmem

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

Example

Owner process

use std::error::Error;
use typed_shmem as sh;

fn main() -> Result<(), Box<dyn Error>> {
    let mut mem = sh::ShMemCfg::<u32>::default()
         .owner()
         .on_file("test_program".to_string())
         .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 std::error::Error;
use typed_shmem as sh;

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

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

    Ok(())
}

Panics

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

Structs

ShMem

Contains the platform-specific implementation details for the 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.