[][src]Crate alloc

A shim crate for to import items of alloc crate ergonomically.

Examples

Usage

Add this to your Cargo.toml:

[dependencies]
alloc-shim = "0.3.0"

Set the features so that std depends on alloc-shim/std, and alloc depends on alloc-shim/alloc:

[features]
std = ["alloc-shim/std"]
alloc = ["alloc-shim/alloc"]

Add this to your crate root (lib.rs or main.rs):

This example is not tested
#![cfg_attr(feature = "alloc", feature(alloc))]

Now, you can use alloc-shim:

#[cfg(any(feature = "alloc", feature = "std"))]
use alloc::prelude::*; // And more...

The current version of alloc-shim requires Rust 1.31 or later.

Crate Features

If not either std or alloc is specified, this crate does nothing.

  • std

    • Disabled by default.
    • Enable to use std crate.
  • alloc

    • Disabled by default.
    • Enable to use alloc crate.
    • Note that std crate is used if both std and alloc are specified at the same time.
    • This requires Rust Nightly.
  • futures

    • Disabled by default.
    • Enable to use alloc::task.
    • This requires Rust Nightly.

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 Strings.

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.

vec

A contiguous growable array type with heap-allocated contents, written Vec<T>.

prelude[
Experimental
]

The alloc Prelude

sync

Synchronization primitives

Macros

format

Creates a String using interpolation of runtime expressions.

vec

Creates a Vec containing the arguments.