Skip to content

Commit

Permalink
Use allocator-api2 only on stable
Browse files Browse the repository at this point in the history
Keep feature semantics
  • Loading branch information
zakarumych committed May 10, 2023
1 parent f04be75 commit edd4f9d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ path = "tests/try_alloc.rs"
harness = false

[dependencies]
allocator-api2 = { version = "0.2.7-rc.1", default-features = false, optional = true, features = ["alloc"] }
allocator-api2 = { version = "0.2.8", default-features = false, optional = true, features = ["alloc"] }

[dev-dependencies]
quickcheck = "1.0.3"
Expand All @@ -42,8 +42,7 @@ rand = "0.8.5"
default = []
collections = []
boxed = []
allocator_api = ["allocator-api2"]
nightly = ["allocator_api"]
allocator_api = []

# [profile.bench]
# debug = true
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![deny(missing_debug_implementations)]
#![deny(missing_docs)]
#![no_std]
#![cfg_attr(feature = "nightly", feature(allocator_api))]
#![cfg_attr(feature = "allocator_api", feature(allocator_api))]

#[doc(hidden)]
pub extern crate alloc as core_alloc;
Expand All @@ -24,10 +24,10 @@ use core::slice;
use core::str;
use core_alloc::alloc::{alloc, dealloc, Layout};

#[cfg(feature = "nightly")]
#[cfg(feature = "allocator_api")]
use core_alloc::alloc::{AllocError, Allocator};

#[cfg(all(feature = "allocator_api", not(feature = "nightly")))]
#[cfg(all(feature = "allocator-api2", not(feature = "allocator_api")))]
use allocator_api2::alloc::{AllocError, Allocator};

pub use alloc::AllocErr;
Expand Down Expand Up @@ -1887,7 +1887,7 @@ unsafe impl<'a> alloc::Alloc for &'a Bump {
}
}

#[cfg(feature = "allocator_api")]
#[cfg(any(feature = "allocator_api", feature = "allocator-api2"))]
unsafe impl<'a> Allocator for &'a Bump {
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
self.try_alloc_layout(layout)
Expand Down

0 comments on commit edd4f9d

Please sign in to comment.