Skip to content

Commit b842177

Browse files
committed
Add the alloc::prelude module
It contains the re-exports that are in `std::prelude::v1` but not in `core::prelude::v1`. Calling it prelude is somewhat of a misnomer since (unlike those modules in `std` or `core`) its contents are never implicitly imported in modules. Rather it is intended to be used with an explicit glob import like `use alloc::prelude::*;`. However there is precedent for the same misnomer with `std::io::prelude`, for example. This new module is unstable with the same feature name as the `alloc` care. They are proposed for stabilization together in RFC rust-lang/rfcs#2480
1 parent e06c875 commit b842177

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/liballoc/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ pub mod collections;
169169
pub mod sync;
170170
pub mod rc;
171171
pub mod raw_vec;
172-
172+
pub mod prelude;
173173
pub mod borrow;
174174
pub mod fmt;
175175
pub mod slice;

src/liballoc/prelude.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2018 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+
//! The alloc Prelude
12+
//!
13+
//! The purpose of this module is to alleviate imports of commonly-used
14+
//! items of the `alloc` crate by adding a glob import to the top of modules:
15+
//!
16+
//! ```
17+
//! # #![allow(unused_imports)]
18+
//! # #![feature(alloc)]
19+
//! extern crate alloc;
20+
//! use alloc::prelude::*;
21+
//! ```
22+
23+
#![unstable(feature = "alloc", issue = "27783")]
24+
25+
#[unstable(feature = "alloc", issue = "27783")] pub use borrow::ToOwned;
26+
#[unstable(feature = "alloc", issue = "27783")] pub use boxed::Box;
27+
#[unstable(feature = "alloc", issue = "27783")] pub use slice::SliceConcatExt;
28+
#[unstable(feature = "alloc", issue = "27783")] pub use string::{String, ToString};
29+
#[unstable(feature = "alloc", issue = "27783")] pub use vec::Vec;

0 commit comments

Comments
 (0)