alloc - Rust
Description: API documentation for the Rust `alloc` crate.
Keywords: rust, rustlang, rust-lang, alloc

# [−][src]Crate alloc

🔬 This is a nightly-only experimental API. (`alloc` #27783)

this library is unlikely to be stabilized in its current form or name

# The Rust core allocation and collections library

This library provides smart pointers and collections for managing heap-allocated values.

This library, like libcore, normally doesn’t need to be used directly since its contents are re-exported in the `std` crate. Crates that use the `#![no_std]` attribute however will typically not depend on `std`, so they’d use this crate instead.

## Boxed values

The `Box` type is a smart pointer type. There can only be one owner of a `Box`, and the owner can decide to mutate the contents, which live on the heap.

This type can be sent among threads efficiently as the size of a `Box` value is the same as that of a pointer. Tree-like data structures are often built with boxes because each node often has only one owner, the parent.

## Reference counted pointers

The `Rc` type is a non-threadsafe reference-counted pointer type intended for sharing memory within a thread. An `Rc` pointer wraps a type, `T`, and only allows access to `&T`, a shared reference.

This type is useful when inherited mutability (such as using `Box`) is too constraining for an application, and is often paired with the `Cell` or `RefCell` types in order to allow mutation.

## Atomically reference counted pointers

The `Arc` type is the threadsafe equivalent of the `Rc` type. It provides all the same functionality of `Rc`, except it requires that the contained type `T` is shareable. Additionally, `Arc<T>` is itself sendable while `Rc<T>` is not.

This type allows for shared access to the contained data, and is often paired with synchronization primitives such as mutexes to allow mutation of shared resources.

## Collections

Implementations of the most common general purpose data structures are defined in this library. They are re-exported through the standard collections library.

## Heap interfaces

The `alloc` module defines the low-level interface to the default global allocator. It is not compatible with the libc allocator API.

## Modules

alloc | Memory allocation APIs
borrow | A module for working with borrowed data.
boxed | A pointer type for heap allocation.
collections | Collection types.
fmt | Utilities for formatting and printing `String`s.
rc | Single-threaded reference-counting pointers. 'Rc' stands for 'Reference Counted'.
slice | A dynamically-sized view into a contiguous sequence, `[T]`.
str | Unicode string slices.
string | A UTF-8 encoded, growable string.
sync | Thread-safe reference-counting pointers.
vec | A contiguous growable array type with heap-allocated contents, written `Vec<T>`.
prelude | [ Experimental ] The alloc Prelude
task | [ Experimental ] Types and Traits for working with asynchronous tasks.

## Macros

format | Creates a `String` using interpolation of runtime expressions.
vec | Creates a `Vec` containing the arguments.

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g. `str,u8` or `String,struct:Vec,test`)