浏览代码

Add collections/alloc features

Jethro Beekman 8 年之前
父节点
当前提交
3b0668806a
共有 3 个文件被更改,包括 42 次插入5 次删除
  1. 5 1
      Cargo.toml
  2. 9 1
      doc.sh
  3. 28 3
      src/lib.rs

+ 5 - 1
Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "core_io"
-version = "0.0.20160708"
+version = "0.1.20160708"
 authors = ["The Rust Project Developers", "Jethro Beekman"]
 license = "MIT/Apache-2.0"
 description = """
@@ -19,3 +19,7 @@ build = "build.rs"
 
 [build-dependencies]
 rustc_version = "0.1.7"
+
+[features]
+alloc = []
+collections = ["alloc"]

+ 9 - 1
doc.sh

@@ -1,2 +1,10 @@
 #!/bin/bash
-cargo rustdoc -- --html-in-header <(echo '<style type="text/css">.docblock>*, .collapse-toggle, #toggle-all-docs { display: none; } #core_io-show-docblock+p { display: initial }</style>')
+cd "$(dirname "$0")"
+HIDE_DOCBLOCKS='.docblock>*, .collapse-toggle, #toggle-all-docs { display: none; } #core_io-show-docblock+p { display: initial }'
+FIX_ERRORSTRING='.method a.type[title="core_io::ErrorString"]:before { content: "Error"; }'
+rm -rf target/doc
+cargo rustdoc --features collections -- --html-in-header <(echo '<style type="text/css">'"$HIDE_DOCBLOCKS"'</style>')
+mv target/doc target/doc_collections
+cargo rustdoc --features alloc -- --html-in-header <(echo '<style type="text/css">'"$HIDE_DOCBLOCKS $FIX_ERROR_STRING"'</style>')
+mv target/doc target/doc_alloc
+cargo rustdoc -- --html-in-header <(echo '<style type="text/css">'"$HIDE_DOCBLOCKS $FIX_ERROR_STRING"'</style>')

+ 28 - 3
src/lib.rs

@@ -6,10 +6,35 @@
 #![feature(question_mark,const_fn,collections,alloc,unicode,copy_from_slice,str_char)]
 #![no_std]
 
-#[macro_use]
-extern crate collections;
-extern crate alloc;
+#[cfg_attr(feature="collections",macro_use)]
+#[cfg(feature="collections")] extern crate collections;
+#[cfg(feature="alloc")] extern crate alloc;
 extern crate rustc_unicode;
 
+#[cfg(not(feature="collections"))]
+pub type ErrorString = &'static str;
+
+// Provide Box::new wrapper
+#[cfg(not(feature="alloc"))]
+struct FakeBox<T>(core::marker::PhantomData<T>);
+#[cfg(not(feature="alloc"))]
+impl<T> FakeBox<T> {
+	fn new(val: T) -> T {
+		val
+	}
+}
+
+// Needed for older compilers, to ignore vec!/format! macros in tests
+#[cfg(not(feature="collections"))]
+macro_rules! vec (
+	( $ elem : expr ; $ n : expr ) => { () };
+	( $ ( $ x : expr ) , * ) => { () };
+	( $ ( $ x : expr , ) * ) => { () };
+);
+#[cfg(not(feature="collections"))]
+macro_rules! format {
+	( $ ( $ arg : tt ) * ) => { () };
+}
+
 include!(concat!(env!("OUT_DIR"), "/io.rs"));
 pub use io::*;