Skip to content

Commit fc5e064

Browse files
bonziniBennoLossin
authored andcommitted
lib: make InPlaceInit available even without alloc feature
The only dependency of the InPlaceInit trait on the allocator API is the AllocError type. Replace it with Infallible instead, i.e. allow any error as long as it has an "impl From<Infallible> for MyError" - which can have a trivial implementation as seen in examples/rror.rs. While admittedly of limited usefulness due to orphan rules, this is a first step towards allowing usage of pinned_init entirely without the allocator API, and therefore on stable Rust. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent da5a88a commit fc5e064

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@ use core::{
256256
#[cfg(feature = "alloc")]
257257
use core::alloc::AllocError;
258258

259+
// Allocations are infallible without the allocator API. In that case, just
260+
// require From<Infallible> for the trait that is passed to the try_* macros,
261+
#[cfg(not(feature = "alloc"))]
262+
type AllocError = Infallible;
263+
259264
#[doc(hidden)]
260265
pub mod __internal;
261266
#[doc(hidden)]
@@ -1153,7 +1158,6 @@ unsafe impl<T, E> PinInit<T, E> for T {
11531158
}
11541159

11551160
/// Smart pointer that can initialize memory in-place.
1156-
#[cfg(feature = "alloc")]
11571161
pub trait InPlaceInit<T>: Sized {
11581162
/// Use the given pin-initializer to pin-initialize a `T` inside of a new smart pointer of this
11591163
/// type.

0 commit comments

Comments
 (0)