]> git.proxmox.com Git - rustc.git/blame - src/doc/edition-guide/src/rust-next/alloc.md
New upstream version 1.53.0+dfsg1
[rustc.git] / src / doc / edition-guide / src / rust-next / alloc.md
CommitLineData
3dfed10e
XL
1# The alloc crate
2
3Initially added: ![Minimum Rust version: 1.36](https://img.shields.io/badge/Minimum%20Rust%20Version-1.36-brightgreen.svg)
4
5Before 1.36.0, the standard library consisted of the crates `std`, `core`, and `proc_macro`.
6The `core` crate provided core functionality such as `Iterator` and `Copy`
7and could be used in `#![no_std]` environments since it did not impose any requirements.
8Meanwhile, the `std` crate provided types like `Box<T>` and OS functionality
9but required a global allocator and other OS capabilities in return.
10
11Starting with Rust 1.36.0, the parts of `std` that depend on a global allocator, e.g. `Vec<T>`,
12are now available in the `alloc` crate. The `std` crate then re-exports these parts.
13While `#![no_std]` *binaries* using `alloc` still require nightly Rust,
14`#![no_std]` *library* crates can use the `alloc` crate in stable Rust.
15Meanwhile, normal binaries, without `#![no_std]`, can depend on such library crates.
16We hope this will facilitate the development of a `#![no_std]` compatible ecosystem of libraries
17prior to stabilizing support for `#![no_std]` binaries using `alloc`.
18
19If you are the maintainer of a library that only relies on some allocation primitives to function,
20consider making your library `#[no_std]` compatible by using the following at the top of your `lib.rs` file:
21
22```rust,ignore
23#![no_std]
24
25extern crate alloc;
26
27use alloc::vec::Vec;
28```