Skip to content

Commit

Permalink
Ready 0.5 release.
Browse files Browse the repository at this point in the history
Signed-off-by: Tin Švagelj <[email protected]>
  • Loading branch information
Caellian committed Mar 22, 2024
1 parent 1073272 commit 56b4c2d
Show file tree
Hide file tree
Showing 14 changed files with 302 additions and 534 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ path = "examples/ptr_metadata.rs"
required-features = ["ptr_metadata"]

[features]
default = ["unsafe_impl", "ptr_metadata", "debug"]
default = ["unsafe_impl", "debug"]

no_std = [] # No-std support
debug = [] # Enable debug attributes
debug = [] # Enable debug attributes

# Implementations
unsafe_impl = []
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# contiguous_mem

contiguous_mem is a vector like collection that can store entries with
heterogeneous layouts while retaining type safety at the reference level.
heterogeneous layouts while retaining type information at the reference level.

[![Crate](https://img.shields.io/crates/v/contiguous_mem?style=for-the-badge&logo=docs.rs)](https://crates.io/crates/contiguous_mem)
[![Documentation](https://img.shields.io/docsrs/contiguous-mem?style=for-the-badge&logo=rust)](https://docs.rs/contiguous-mem)
Expand Down Expand Up @@ -32,7 +32,8 @@ over when your scope and requirements shift.
## Use cases

- Storing differently typed/sized data. ([example](./examples/default_impl.rs))
- Ensuring stored data is placed adjacently in memory. ([example](./examples/game_loading.rs))
- Ensuring stored data is placed adjacently in memory.
([example](./examples/game_loading.rs))
- Note that returned references are **not** contiguous, only data they refer
to is.

Expand All @@ -42,14 +43,14 @@ Add the crate to your dependencies:

```toml
[dependencies]
contiguous_mem = { version = "0.4" }
contiguous_mem = { version = "0.5" }
```

Optionally enable `no_std` feature to use in `no_std` environment:

```toml
[dependencies]
contiguous_mem = { version = "0.4", features = ["no_std"] }
contiguous_mem = { version = "0.5", features = ["no_std"] }
```

### Features
Expand Down
2 changes: 1 addition & 1 deletion doc/crate.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
contiguous_mem is a vector like collection that can store entries with
heterogeneous layouts while retaining type safety at the reference level.
heterogeneous layouts while retaining type information at the reference level.

## Features

Expand Down
247 changes: 0 additions & 247 deletions doc/struct.md

This file was deleted.

4 changes: 4 additions & 0 deletions examples/default_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ fn main() {
// Retrieve and use the stored data
assert_eq!(*stored_data.get(), data);
assert_eq!(*stored_number.get(), 22);

// All stored data gets cleaned up once `memory` goes out of scope, or we
// can forget it existed:
memory.forget();
}
7 changes: 6 additions & 1 deletion examples/unsafe_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ struct Data {
}

fn main() {
// Create a ContiguousMemory instance with a capacity of 1024 bytes and 1-byte alignment
// Create a ContiguousMemory instance with a capacity of 1024 bytes and
// 1-byte alignment
let mut memory = ContiguousMemory::<ImplUnsafe>::with_capacity(1024);

// Store data in the memory container
Expand All @@ -22,4 +23,8 @@ fn main() {
assert!(!stored_number.is_null());
assert_eq!(*stored_number, 22);
}

// All stored data gets cleaned up once `memory` goes out of scope, or we
// can forget it existed:
memory.forget();
}
25 changes: 14 additions & 11 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,34 @@
#[cfg(any(feature = "error_in_core", not(feature = "no_std")))]
use crate::types::Error;

use core::fmt::Debug;
#[cfg(any(not(feature = "no_std"), feature = "error_in_core"))]
use core::fmt::{Display, Formatter, Result as FmtResult};
use core::{cell::Ref, fmt::Debug};

use crate::{
memory::ManageMemory,
range::ByteRange,
reference::BorrowState,
types::{ImplDetails, ImplReferencing, ReadableInner, WritableInner},
};
use crate::{range::ByteRange, reference::BorrowState};

/// Represents a class of errors returned by invalid memory operations and
/// allocator failiure.
/// allocator failure.
#[derive(Debug, Clone, Copy)]
pub enum MemoryError {
/// Tried allocating container capacity larger than `isize::MAX`
TooLarge,
/// Allocation failure caused by either resource exhaustion or invalid
/// arguments being provided to an allocator.
Allocator(
#[cfg(feature = "allocator_api")] core::alloc::AllocError,
/// Cause allocator error.
#[cfg(feature = "allocator_api")]
core::alloc::AllocError,
#[cfg(not(feature = "allocator_api"))] (),
),
}

impl From<core::alloc::LayoutError> for MemoryError {
fn from(_: core::alloc::LayoutError) -> Self {
Self::TooLarge
}
}

#[cfg(any(not(feature = "no_std"), feature = "error_in_core"))]
impl Display for MemoryError {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
Expand Down Expand Up @@ -59,8 +62,8 @@ impl From<core::alloc::AllocError> for MemoryError {
}
}

/// Error returned when concurrent mutable access is attempted to the same
/// memory region.
/// Error returned when concurrent mutable access to the same memory region is
/// attempted.
#[derive(Debug)]
pub struct RegionBorrowError {
/// Range that was attempted to be borrowed.
Expand Down
Loading

0 comments on commit 56b4c2d

Please sign in to comment.