From 8083aa541e1951d0f1d81336ba3d20a6f9bd3200 Mon Sep 17 00:00:00 2001 From: Tin Svagelj Date: Mon, 28 Aug 2023 09:17:38 +0200 Subject: [PATCH] Fix issues with the previous release Remove ptr_metadata from default dependencies Fix compiler errors when the crate is compiled without ptr_metadata feature. Signed-off-by: Tin Svagelj --- Cargo.toml | 4 ++-- README.md | 17 ++++++++++++++--- src/error.rs | 2 +- src/lib.rs | 8 ++++++-- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c11fdfc..db2777b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "contiguous-mem" -version = "0.1.1" +version = "0.1.2" edition = "2021" description = "A contiguous memory storage" authors = ["Tin Å vagelj "] @@ -20,7 +20,7 @@ portable-atomic = { version = "1", default-features = false } spin = { version = "0.9", optional = true } [features] -default = ["std", "ptr_metadata"] +default = ["std"] std = ["portable-atomic/std"] no_std = ["dep:spin"] debug = [] diff --git a/README.md b/README.md index 1ba4473..af2a068 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ # contiguous_mem -Contiguous memory is memory that is allocated in one contiguous block. +contiguous_mem implements a contiguous memory storage container for arbitrary data types. + +[![Crates.io](https://img.shields.io/crates/v/contiguous_mem)](https://crates.io/crates/contiguous_mem) +[![Documentation](https://docs.rs/contiguous_mem/badge.svg)](https://docs.rs/contiguous_mem) + Designed for both standard and no_std environments, this library ensures efficient memory allocation while being simple and (somewhat) safe to use. ## Key Features @@ -18,14 +22,14 @@ Add the crate to your dependencies: ```toml [dependencies] -contiguous_mem = "0.1.0" +contiguous_mem = "0.1.*" ``` Optionally disable the `std` feature and enable `no_std` feature to use in `no_std` environment: ```toml [dependencies] -contiguous_mem = { version = "0.1.0", default-features = false, features = ["no_std"] } +contiguous_mem = { version = "0.1.*", default-features = false, features = ["no_std"] } ``` ### Example usage @@ -54,6 +58,13 @@ fn main() { } ``` +### Features + +- `std` (default) - enables support for `std` environment +- `no_std` - enables support for `no_std` environment +- `debug` - enables `derive(Debug)` on structures +- `ptr_metadata` - enables support for casting returned references into `dyn Trait` types + ## Contributions Contributions are welcome, feel free to create an issue or a pull request. diff --git a/src/error.rs b/src/error.rs index 76885af..3b49853 100644 --- a/src/error.rs +++ b/src/error.rs @@ -38,7 +38,7 @@ pub enum ContiguousMemoryError { pub enum PoisonedMutex { /// Mutex containing the base memory offset was poisoned. BaseAddress, - /// [`AllocationTracker`] mutex was poisoned. + /// [`AllocationTracker`](crate::AllocationTracker) mutex was poisoned. AllocationTracker, } diff --git a/src/lib.rs b/src/lib.rs index bdd4f86..7a75b4b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,12 +17,15 @@ pub mod error; use core::{ cell::{Cell, RefCell}, mem::size_of, - ptr::{null_mut, write_unaligned, Pointee}, + ptr::{null_mut, write_unaligned}, }; #[cfg(not(feature = "ptr_metadata"))] use core::marker::PhantomData; +#[cfg(feature = "ptr_metadata")] +use core::ptr::Pointee; + #[cfg(feature = "std")] mod std_imports { pub use std::alloc::{Layout, LayoutError}; @@ -1045,6 +1048,7 @@ impl Drop for ContiguousMemory { } /// A reference to `T` data stored in a [`ContiguousMemory`] structure. +#[cfg_attr(feature = "debug", derive(Debug))] pub struct CMRef { base: S::Base, range: ByteRange, @@ -1078,7 +1082,7 @@ impl CMRef { } #[cfg(not(feature = "ptr_metadata"))] -impl CMRef { +impl CMRef { /// Tries accessing referenced data at its current location. /// /// Returns a [`Poisoned`](ContiguousMemoryError::Poisoned) error if the Mutex