Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
with:
tool: just,cargo-hack,cargo-sync-rdme
- name: Lint (clippy)
run: just powerset --partition ${{ matrix.partition }}/10 clippy --all-targets
run: just powerset --exclude-features nightly --partition ${{ matrix.partition }}/10 clippy --all-targets
- name: Lint (rustfmt)
run: cargo xfmt --check
- name: Run rustdoc
Expand Down Expand Up @@ -67,11 +67,11 @@ jobs:
- uses: taiki-e/install-action@just
- uses: taiki-e/install-action@nextest
- name: Build
run: just powerset --partition ${{ matrix.partition }}/10 build
run: just powerset --exclude-features nightly --partition ${{ matrix.partition }}/10 build
- name: Run tests
run: just powerset --partition ${{ matrix.partition }}/10 nextest run
run: just powerset --exclude-features nightly --partition ${{ matrix.partition }}/10 nextest run
- name: Doctests
run: just powerset --partition ${{ matrix.partition }}/10 test --doc
run: just powerset --exclude-features nightly --partition ${{ matrix.partition }}/10 test --doc

build-no-std:
name: Build on no-std
Expand Down
1 change: 1 addition & 0 deletions crates/iddqd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ allocator-api2 = ["iddqd-test-utils/allocator-api2"]
daft = ["dep:daft", "dep:ref-cast"]
default = ["allocator-api2", "std", "default-hasher"]
default-hasher = ["dep:foldhash", "iddqd-test-utils/default-hasher"]
nightly = []
proptest = ["dep:proptest"]
schemars08 = ["dep:schemars", "dep:serde_json", "serde"]
serde = ["dep:serde_core", "iddqd-test-utils/serde"]
Expand Down
4 changes: 4 additions & 0 deletions crates/iddqd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ platform-specific notion of thread locals, would suffice to make
* `default-hasher`: Enables the `DefaultHashBuilder` type. Disable this
feature to require a hash builder type parameter to be passed into
[`IdHashMap`](https://docs.rs/iddqd/0.4.0/iddqd/id_hash_map/imp/struct.IdHashMap.html), [`BiHashMap`](https://docs.rs/iddqd/0.4.0/iddqd/bi_hash_map/imp/struct.BiHashMap.html), and [`TriHashMap`](https://docs.rs/iddqd/0.4.0/iddqd/tri_hash_map/imp/struct.TriHashMap.html). *Enabled by default.*
* `nightly`: Enables support for the nightly `core::alloc::Allocator` trait.
Requires a nightly Rust compiler. When enabled, map types accept any type
implementing `core::alloc::Allocator` as a custom allocator. *Not enabled
by default.*
* `proptest`: Enables [`proptest`](https://docs.rs/proptest/1.7.0/proptest/index.html) support for all ID map types, providing
[`Arbitrary`] implementations and strategies for property-based testing.
*Not enabled by default.*
Expand Down
5 changes: 5 additions & 0 deletions crates/iddqd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@
//! - `default-hasher`: Enables the `DefaultHashBuilder` type. Disable this
//! feature to require a hash builder type parameter to be passed into
//! [`IdHashMap`], [`BiHashMap`], and [`TriHashMap`]. *Enabled by default.*
//! - `nightly`: Enables support for the nightly `core::alloc::Allocator` trait.
//! Requires a nightly Rust compiler. When enabled, map types accept any type
//! implementing `core::alloc::Allocator` as a custom allocator. *Not enabled
//! by default.*
//! - `proptest`: Enables [`proptest`] support for all ID map types, providing
//! [`Arbitrary`] implementations and strategies for property-based testing.
//! *Not enabled by default.*
Expand Down Expand Up @@ -367,6 +371,7 @@

#![no_std]
#![cfg_attr(doc_cfg, feature(doc_cfg))]
#![cfg_attr(feature = "nightly", feature(allocator_api))]
#![warn(missing_docs)]

#[cfg_attr(not(feature = "std"), macro_use)] // for `format!`
Expand Down
29 changes: 27 additions & 2 deletions crates/iddqd/src/support/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
pub use self::inner::Global;
pub(crate) use self::inner::{AllocWrapper, Allocator, global_alloc};

// TODO: support nightly.

// Basic non-nightly case.
#[cfg(feature = "allocator-api2")]
mod inner {
Expand Down Expand Up @@ -103,3 +101,30 @@ mod inner {
}
}
}

// Nightly support: implement `core::alloc::Allocator` for `AllocWrapper`.
// This bridges `allocator_api2::alloc::Allocator` types to the nightly
// `core::alloc::Allocator` trait, allowing `AllocWrapper` to be used where
// the standard library allocator trait is expected.
#[cfg(feature = "nightly")]
// SAFETY: These functions just forward to the wrapped allocator.
unsafe impl<T: Allocator> alloc::alloc::Allocator for AllocWrapper<T> {
#[inline]
fn allocate(
&self,
layout: alloc::alloc::Layout,
) -> Result<core::ptr::NonNull<[u8]>, alloc::alloc::AllocError> {
Allocator::allocate(&self.0, layout)
.map_err(|_| alloc::alloc::AllocError)
}

#[inline]
unsafe fn deallocate(
&self,
ptr: core::ptr::NonNull<u8>,
layout: alloc::alloc::Layout,
) {
// SAFETY: caller upholds safety contract.
unsafe { Allocator::deallocate(&self.0, ptr, layout) }
}
}
Loading