|
| 1 | +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT |
| 2 | +// file at the top-level directory of this distribution and at |
| 3 | +// http://rust-lang.org/COPYRIGHT. |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | +// option. This file may not be copied, modified, or distributed |
| 9 | +// except according to those terms. |
| 10 | + |
| 11 | +//! Rust's core allocation library |
| 12 | +//! |
| 13 | +//! This is the lowest level library through which allocation in Rust can be |
| 14 | +//! performed where the allocation is assumed to succeed. This library will |
| 15 | +//! trigger a task failure when allocation fails. |
| 16 | +//! |
| 17 | +//! This library, like libcore, is not intended for general usage, but rather as |
| 18 | +//! a building block of other libraries. The types and interfaces in this |
| 19 | +//! library are reexported through the [standard library](../std/index.html), |
| 20 | +//! and should not be used through this library. |
| 21 | +//! |
| 22 | +//! Currently, there are four major definitions in this library. |
| 23 | +//! |
| 24 | +//! ## Owned pointers |
| 25 | +//! |
| 26 | +//! The [`Box`](owned/index.html) type is the core owned pointer type in rust. |
| 27 | +//! There can only be one owner of a `Box`, and the owner can decide to mutate |
| 28 | +//! the contents. |
| 29 | +//! |
| 30 | +//! This type can be sent among tasks efficiently as the size of a `Box` value |
| 31 | +//! is just a pointer. Tree-like data structures are often built on owned |
| 32 | +//! pointers because each node often has only one owner, the parent. |
| 33 | +//! |
| 34 | +//! ## Reference counted pointers |
| 35 | +//! |
| 36 | +//! The [`Rc`](rc/index.html) type is a non-threadsafe reference-counted pointer |
| 37 | +//! type intended for sharing memory within a task. An `Rc` pointer wraps a |
| 38 | +//! type, `T`, and only allows access to `&T`, a shared reference. |
| 39 | +//! |
| 40 | +//! This type is useful when inherited mutability is too constraining for an |
| 41 | +//! application (such as using `Box`), and is often paired with the `Cell` or |
| 42 | +//! `RefCell` types in order to allow mutation. |
| 43 | +//! |
| 44 | +//! ## Atomically reference counted pointers |
| 45 | +//! |
| 46 | +//! The [`Arc`](arc/index.html) type is the threadsafe equivalent of the `Rc` |
| 47 | +//! type. It provides all the same functionality of `Rc`, except it requires |
| 48 | +//! that the contained type `T` is shareable. Additionally, `Arc<T>` is itself |
| 49 | +//! sendable while `Rc<T>` is not. |
| 50 | +//! |
| 51 | +//! This types allows for shared access to the contained data, and is often |
| 52 | +//! paired with synchronization primitives such as mutexes to allow mutation of |
| 53 | +//! shared resources. |
| 54 | +//! |
| 55 | +//! ## Heap interfaces |
| 56 | +//! |
| 57 | +//! The [`heap`](heap/index.html) and [`libc_heap`](libc_heap/index.html) |
| 58 | +//! modules are the unsafe interfaces to the underlying allocation systems. The |
| 59 | +//! `heap` module is considered the default heap, and is not necessarily backed |
| 60 | +//! by libc malloc/free. The `libc_heap` module is defined to be wired up to |
| 61 | +//! the system malloc/free. |
| 62 | +
|
| 63 | +#![crate_id = "alloc#0.11.0-pre"] |
| 64 | +#![license = "MIT/ASL2"] |
| 65 | +#![crate_type = "rlib"] |
| 66 | +#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", |
| 67 | + html_favicon_url = "http://www.rust-lang.org/favicon.ico", |
| 68 | + html_root_url = "http://static.rust-lang.org/doc/master")] |
| 69 | + |
| 70 | +#![no_std] |
| 71 | +#![feature(phase)] |
| 72 | + |
| 73 | +#[phase(syntax, link)] |
| 74 | +extern crate core; |
| 75 | +extern crate libc; |
| 76 | + |
| 77 | +// Allow testing this library |
| 78 | + |
| 79 | +#[cfg(test)] extern crate sync; |
| 80 | +#[cfg(test)] extern crate native; |
| 81 | +#[cfg(test)] #[phase(syntax, link)] extern crate std; |
| 82 | +#[cfg(test)] #[phase(syntax, link)] extern crate log; |
| 83 | + |
| 84 | +// Heaps provided for low-level allocation strategies |
| 85 | + |
| 86 | +pub mod heap; |
| 87 | +pub mod libc_heap; |
| 88 | +pub mod util; |
| 89 | + |
| 90 | +// Primitive types using the heaps above |
| 91 | + |
| 92 | +#[cfg(not(test))] |
| 93 | +pub mod owned; |
| 94 | +pub mod arc; |
| 95 | +pub mod rc; |
| 96 | + |
| 97 | +#[cfg(not(test))] |
| 98 | +mod std { |
| 99 | + pub use core::fmt; |
| 100 | + pub use core::option; |
| 101 | +} |
0 commit comments