Skip to content

Commit

Permalink
Fix issues with the previous release
Browse files Browse the repository at this point in the history
Remove ptr_metadata from default dependencies
Fix compiler errors when the crate is compiled without ptr_metadata
feature.

Signed-off-by: Tin Svagelj <tin.svagelj@live.com>
  • Loading branch information
Caellian committed Aug 28, 2023
1 parent 6e77656 commit 8083aa5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <tin.svagelj@live.com>"]
Expand All @@ -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 = []
Expand Down
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -1045,6 +1048,7 @@ impl<S: ImplDetails> Drop for ContiguousMemory<S> {
}

/// A reference to `T` data stored in a [`ContiguousMemory`] structure.
#[cfg_attr(feature = "debug", derive(Debug))]
pub struct CMRef<T: ?Sized, S: ImplDetails = NotThreadSafeImpl> {
base: S::Base,
range: ByteRange,
Expand Down Expand Up @@ -1078,7 +1082,7 @@ impl<T: Sized, S: ImplDetails> CMRef<T, S> {
}

#[cfg(not(feature = "ptr_metadata"))]
impl<T: ?Sized, S: ImplDetails> CMRef<T, S> {
impl<T: Sized, S: ImplDetails> CMRef<T, S> {
/// Tries accessing referenced data at its current location.
///
/// Returns a [`Poisoned`](ContiguousMemoryError::Poisoned) error if the Mutex
Expand Down

0 comments on commit 8083aa5

Please sign in to comment.