#no-std #allocator

no-std allocator_api

This is a copy of the unstable allocator_api (https://github.com/rust-lang/rust/issues/32838) and of parts of the unstable alloc feature. Usable with stable rust, but requires 1.33

9 releases (breaking)

0.6.0 Apr 24, 2019
0.5.0 Jun 26, 2018
0.4.0 Jun 12, 2018
0.3.0 May 16, 2018
0.0.1 Mar 28, 2018

#177 in Memory management

Download history 423/week @ 2022-11-27 290/week @ 2022-12-04 499/week @ 2022-12-11 107/week @ 2022-12-18 148/week @ 2022-12-25 239/week @ 2023-01-01 266/week @ 2023-01-08 235/week @ 2023-01-15 69/week @ 2023-01-22 383/week @ 2023-01-29 340/week @ 2023-02-05 283/week @ 2023-02-12 446/week @ 2023-02-19 247/week @ 2023-02-26 497/week @ 2023-03-05 424/week @ 2023-03-12

1,622 downloads per month
Used in boxext

Apache-2.0/MIT

96KB
1K SLoC

allocator_api

This is a copy of the unstable allocator_api (https://github.com/rust-lang/rust/issues/32838) and of parts of the unstable alloc feature.

Usable with stable rust, but requires 1.33.

Differences with nightly rust

The code was copied from the rust code as of 1.34.0 with #[stable] annotations and #[unstable] implementations removed.

In the alloc module (corresponding to parts of both core::alloc and std::alloc), the oom function infinitely loops instead of calling core::intrinsics::abort, which is not stable. Users of this crate should use set_oom_hook to set their own oom function that aborts in the right way (in non-no_std cases, one can use process::abort()).

In the raw_vec module (corresponding to alloc::raw_vec), RawVec uses NonNull instead of Unique.

In the boxed module (corresponding to alloc::boxed), the Box type is augmented such that it is associated with an allocator, similarly to RawVec. Its API is consequently slightly different from std::boxed::Box (e.g. from_raw is replaced with from_raw_in). The same (stable) features as std::boxed::Box are implemented, except for downcast for Box<Any> and Box<Any + Send>. Like for RawVec, the type relies on NonNull rather than Unique.

Caveat: the types provided in this crate cannot be used where the corresponding types from std/alloc are expected. Few APIs should be taking those types directly as input, though.

No runtime deps

Features

  • std