diff --git a/src/allocator/boxed.rs b/src/allocator/boxed.rs new file mode 100644 index 00000000..9d27af95 --- /dev/null +++ b/src/allocator/boxed.rs @@ -0,0 +1,4 @@ +#[cfg(not(feature = "allocator-api2"))] +pub use alloc::boxed::Box; +#[cfg(feature = "allocator-api2")] +pub use allocator_api2::boxed::Box; diff --git a/src/allocator/global.rs b/src/allocator/global.rs new file mode 100644 index 00000000..67af50c6 --- /dev/null +++ b/src/allocator/global.rs @@ -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; diff --git a/src/allocator/base.rs b/src/allocator/implementations/base.rs similarity index 94% rename from src/allocator/base.rs rename to src/allocator/implementations/base.rs index 76ec54e8..996586fd 100644 --- a/src/allocator/base.rs +++ b/src/allocator/implementations/base.rs @@ -1,5 +1,8 @@ use { - super::Allocator, + super::super::{ + Allocator, + global::Global + }, alloc::alloc::{ alloc, dealloc, @@ -11,9 +14,6 @@ use { } }; -#[derive(Clone)] -pub struct Global; - impl Allocator for Global { #[inline] fn allocate(&self, layout: Layout) -> Option> { diff --git a/src/allocator/external.rs b/src/allocator/implementations/external.rs similarity index 96% rename from src/allocator/external.rs rename to src/allocator/implementations/external.rs index 635a8697..72083f23 100644 --- a/src/allocator/external.rs +++ b/src/allocator/implementations/external.rs @@ -1,5 +1,5 @@ use { - super::Allocator, + super::super::Allocator, allocator_api2::alloc::Allocator as External, core::{ alloc::Layout, diff --git a/src/allocator/implementations/mod.rs b/src/allocator/implementations/mod.rs new file mode 100644 index 00000000..59ab2e1e --- /dev/null +++ b/src/allocator/implementations/mod.rs @@ -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; diff --git a/src/allocator/native.rs b/src/allocator/implementations/native.rs similarity index 96% rename from src/allocator/native.rs rename to src/allocator/implementations/native.rs index 77603616..70ef0866 100644 --- a/src/allocator/native.rs +++ b/src/allocator/implementations/native.rs @@ -1,5 +1,5 @@ use { - super::Allocator, + super::super::Allocator, alloc::alloc::Allocator as Native, core::{ alloc::Layout, diff --git a/src/allocator/mod.rs b/src/allocator/mod.rs index 5e67a3a8..46927df0 100644 --- a/src/allocator/mod.rs +++ b/src/allocator/mod.rs @@ -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>; unsafe fn deallocate(&self, pointer: NonNull, layout: Layout); diff --git a/src/allocator/vec.rs b/src/allocator/vec.rs new file mode 100644 index 00000000..a1181229 --- /dev/null +++ b/src/allocator/vec.rs @@ -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 +}; diff --git a/src/iterators/mod.rs b/src/iterators/mod.rs index 40585e0c..78953514 100644 --- a/src/iterators/mod.rs +++ b/src/iterators/mod.rs @@ -1,7 +1,6 @@ pub mod drain; pub mod extractif; pub mod intoiter; -pub mod splice; - #[cfg(feature = "rayon")] mod rayon; +pub mod splice; diff --git a/src/lib.rs b/src/lib.rs index 9f391826..e487ac98 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -58,10 +58,12 @@ use std::io; use { allocator::{ Allocator, - Box, - Global, - Vec, - vec + boxed::Box, + global::Global, + vec::{ + Vec, + vec + } }, core::{ alloc::Layout,