contiguous_mem
contiguous_mem streamlines storage and management of data stored in contiguous memory block.
Key Features
no_stdsupport!- Simple and straightforward interface similar to standard containers.
- Support for dynamic resizing of allocated memory keeping the created references functional (for safe implementations).
Specialized implementations
You can pick and choose which implementation suits your use case best allowing you to avoid runtime cost of synchronization and additionally memory cost of safely wrapping referenced data if you don't need it.
Default implementation keeps relative offsets of stored data which are resolved on access.
Tradeoffs
-
Works without nightly but leaks data, enable
ptr_metadataor disable defaultleak_datafeature flag if memory leaks are an issue:ptr_metadatarequires nightly,- disabling
leak_dataimposesCopyrequirement on stored types.
-
References returned by
storefunction follow the same borrow restrictions as the language,Derefis implemented forContiguousMemoryRefbut it will panic on dereference if it's been already mutably borrowed somewhere else. UseContiguousMemoryRef::try_getif you'd like to handle that properly.
Getting Started
Add the crate to your dependencies:
[]
= { = "0.3.0" }
Optionally disable the std feature and enable no_std feature to use in no_std environment:
[]
= { = "0.3.0", = false, = ["no_std"] }
Features
std(default) - usestdenvironment sync primitives and locksno_std- enablesno_stddependenciesleak_data(default) - disablesCopyrequirement for stored types, but any references in stored data will be leaked when the memory container is droppeddebug- enablesderive(Debug)on structures unrelated to error handlingptr_metadata<nightly> - enables support for casting returned references intodyn Traittypes as well as cleaning up any types that implementDropor generate drop glueerror_in_core<nightly> - enables support forcore::error::Errorinno_stdenvironment
Usage
use *;
Note that reference types returned by store are inferred and only shown here for demonstration purposes.
Contributions
Contributions are welcome, feel free to create an issue or a pull request.
All contributions to the project are licensed under the Zlib/MIT/Apache 2.0 license unless you explicitly state otherwise.
License
This project is licensed under Zlib, MIT, or Apache-2.0 license, choose whichever suits you most.