Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
win-shared-memory
A typed, RAII Rust library for easy access to named Windows shared memory regions.
Table of Contents
Dependencies and requirements
- Windows only — uses Win32 file-mapping APIs (
CreateFileMappingW,MapViewOfFile, etc.). - Requires Rust edition 2024.
Getting started
Add the library to your project:
Usage
All access goes through SharedMemoryLink<T, Access>, a typed RAII handle that unmaps the view
and closes the handle automatically on drop. The type T describes the layout of the shared
region and must be #[repr(C)] (or another stable layout) so that both processes agree on the
memory layout.
Creating a region (writer process)
use ;
// Create a fresh, zero-initialised region. Fails if the name is already taken.
let mut link: =
create.expect;
unsafe
Use get_or_create instead if you want to open the region when it already exists:
let mut link: =
get_or_create.unwrap;
Opening a region (reader process)
use ;
let link: =
open.expect;
let state = unsafe ;
println!;
Opening an existing region for read-write
A second writer (or any process that did not create the region) can open it for read-write access:
use ;
let mut link: =
open_existing.expect;
unsafe
Access modes
| Type parameter | Constructor(s) | Available methods |
|---|---|---|
ReadOnly |
SharedMemoryLink::open |
get |
ReadWrite |
SharedMemoryLink::create, SharedMemoryLink::get_or_create, SharedMemoryLink::open_existing |
get, get_mut |
Error handling
All constructors return Result<_, SharedMemoryError>. The enum variants are:
| Variant | When |
|---|---|
OpenMapping(windows::core::Error) |
OpenFileMappingW failed (region not found, access denied) |
CreateMapping(windows::core::Error) |
CreateFileMappingW failed |
MapView(windows::core::Error) |
MapViewOfFile returned null |
AlreadyExists |
create was called but the name is already taken |
SizeTooLarge |
size_of::<T>() exceeds u32::MAX |
Safety
get and get_mut are unsafe because shared memory is inherently a cross-process resource.
The library enforces single-process aliasing rules through Rust's borrow checker (get_mut
requires &mut self), but it cannot prevent a remote process from writing concurrently.
Callers are responsible for coordinating cross-process access — for example with a named mutex.
Side notes
Please keep in mind that at the moment this is a side project developed with no planned continuity nor schedule. Therefore support, fixes and new features can not be guaranteed.
As stated in the LICENSE, no contributor must be considered liable for the use of this project.