Skip to content
Merged
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
4 changes: 4 additions & 0 deletions src/allocator/boxed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[cfg(not(feature = "allocator-api2"))]
pub use alloc::boxed::Box;
#[cfg(feature = "allocator-api2")]
pub use allocator_api2::boxed::Box;
7 changes: 7 additions & 0 deletions src/allocator/global.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#[cfg(not(feature = "allocator-api"))]
#[derive(Clone)]
pub struct Global;
#[cfg(all(feature = "allocator-api", not(feature = "allocator-api2")))]
pub use alloc::alloc::Global;
#[cfg(feature = "allocator-api2")]
pub use allocator_api2::alloc::Global;
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use {
super::Allocator,
super::super::{
Allocator,
global::Global
},
alloc::alloc::{
alloc,
dealloc,
Expand All @@ -11,9 +14,6 @@ use {
}
};

#[derive(Clone)]
pub struct Global;

impl Allocator for Global {
#[inline]
fn allocate(&self, layout: Layout) -> Option<NonNull<[u8]>> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use {
super::Allocator,
super::super::Allocator,
allocator_api2::alloc::Allocator as External,
core::{
alloc::Layout,
Expand Down
6 changes: 6 additions & 0 deletions src/allocator/implementations/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[cfg(not(feature = "allocator-api"))]
mod base;
#[cfg(feature = "allocator-api2")]
mod external;
#[cfg(all(feature = "allocator-api", not(feature = "allocator-api2")))]
mod native;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use {
super::Allocator,
super::super::Allocator,
alloc::alloc::Allocator as Native,
core::{
alloc::Layout,
Expand Down
37 changes: 4 additions & 33 deletions src/allocator/mod.rs
Original file line number Diff line number Diff line change
@@ -1,43 +1,14 @@
#[cfg(not(feature = "allocator-api"))]
mod base;
#[cfg(feature = "allocator-api2")]
mod external;
#[cfg(all(feature = "allocator-api", not(feature = "allocator-api2")))]
mod native;
pub mod boxed;
pub mod global;
mod implementations;
pub mod proxy;
pub mod vec;

use core::{
alloc::Layout,
ptr::NonNull
};

#[cfg(not(feature = "allocator-api"))]
#[rustfmt::skip]
pub use {
alloc::{
boxed::Box,
vec::Vec,
vec
},
base::Global
};
#[cfg(feature = "allocator-api2")]
#[rustfmt::skip]
pub use allocator_api2::{
alloc::Global,
boxed::Box,
vec::Vec,
vec
};
#[cfg(all(feature = "allocator-api", not(feature = "allocator-api2")))]
#[rustfmt::skip]
pub use alloc::{
alloc::Global,
boxed::Box,
vec::Vec,
vec
};

pub trait Allocator {
fn allocate(&self, layout: Layout) -> Option<NonNull<[u8]>>;
unsafe fn deallocate(&self, pointer: NonNull<u8>, layout: Layout);
Expand Down
13 changes: 13 additions & 0 deletions src/allocator/vec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#[cfg(not(feature = "allocator-api2"))]
#[rustfmt::skip]
pub use alloc::{
vec,
vec::Vec
};

#[cfg(feature = "allocator-api2")]
#[rustfmt::skip]
pub use allocator_api2::{
vec,
vec::Vec
};
3 changes: 1 addition & 2 deletions src/iterators/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pub mod drain;
pub mod extractif;
pub mod intoiter;
pub mod splice;

#[cfg(feature = "rayon")]
mod rayon;
pub mod splice;
10 changes: 6 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ use std::io;
use {
allocator::{
Allocator,
Box,
Global,
Vec,
vec
boxed::Box,
global::Global,
vec::{
Vec,
vec
}
},
core::{
alloc::Layout,
Expand Down
Loading