Crates.io | contiguous-mem |
lib.rs | contiguous-mem |
version | 0.4.2 |
source | src |
created_at | 2023-08-28 03:25:36.19111 |
updated_at | 2023-09-20 13:43:14.685662 |
description | A contiguous memory storage |
homepage | |
repository | https://github.com/Caellian/contiguous_mem |
max_upload_size | |
id | 956563 |
size | 152,079 |
contiguous_mem streamlines storage and management of data stored in contiguous blocks of memory.
no_std
support!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.
Add the crate to your dependencies:
[dependencies]
contiguous_mem = { version = "0.4" }
Optionally enable no_std
feature to use in no_std
environment:
[dependencies]
contiguous_mem = { version = "0.4", features = ["no_std"] }
no_std
- enables no_std
dependencies for atomics, mutexes and rwlocksdebug
- enables derive(Debug)
on structures unrelated to error handlingptr_metadata
<nightly> - allows casting references into dyn Trait
error_in_core
<nightly> - enables support for core::error::Error
in no_std
environmentuse contiguous_mem::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
struct Data {
value: u32,
}
fn main() {
// Create a ContiguousMemory instance with a capacity of 1024 bytes and 1-byte alignment
let mut memory = ContiguousMemory::new(1024);
// Store data in the memory container
let data = Data { value: 42 };
let stored_number: ContiguousMemoryRef<u64> = memory.push(22u64);
let stored_data: ContiguousMemoryRef<Data> = memory.push(data);
// Retrieve and use the stored data
assert_eq!(*stored_data.get(), data);
assert_eq!(*stored_number.get(), 22);
}
RefCell
Note that reference types returned by store are inferred and only shown here for demonstration purposes.
For more usage examples see the
examples
directory.
All versions prior to 1.0.0 are not considered production ready. This is my first crate and there's still a lot of edge cases I didn't get a chance to consider yet.
Prelimenary tests are in place but I don't consider them sufficient to guarantee full correctness of behavior. I am however using this crate for development of another crate which allows me to do some integration testing besides just examples.
Layout
, when you only need to erase their
types at the container level see:
allocator_api
featureblink-alloc
provides a similar functionality as this crate without the
allocator_api
feature; intended for use in loops so it doesn't support
freeing some values while retaining otherContributions 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.
This project is licensed under Zlib, MIT, or Apache-2.0 license, choose whichever suits you most.