* `stringify!` : pretty-print the Rust expression given as an argument
* `include!` : include the Rust expression in the given file
* `include_str!` : include the contents of the given file as a string
-* `include_bin!` : include the contents of the given file as a binary blob
+* `include_bytes!` : include the contents of the given file as a binary blob
* `error!`, `warn!`, `info!`, `debug!` : provide diagnostic information.
All of the above extensions are expressions with values.
// Add all the static files. These may already exist, but we just
// overwrite them anyway to make sure that they're fresh and up-to-date.
try!(write(cx.dst.join("jquery.js"),
- include_bin!("static/jquery-2.1.0.min.js")));
- try!(write(cx.dst.join("main.js"), include_bin!("static/main.js")));
- try!(write(cx.dst.join("playpen.js"), include_bin!("static/playpen.js")));
- try!(write(cx.dst.join("main.css"), include_bin!("static/main.css")));
+ include_bytes!("static/jquery-2.1.0.min.js")));
+ try!(write(cx.dst.join("main.js"), include_bytes!("static/main.js")));
+ try!(write(cx.dst.join("playpen.js"), include_bytes!("static/playpen.js")));
+ try!(write(cx.dst.join("main.css"), include_bytes!("static/main.css")));
try!(write(cx.dst.join("normalize.css"),
- include_bin!("static/normalize.css")));
+ include_bytes!("static/normalize.css")));
try!(write(cx.dst.join("FiraSans-Regular.woff"),
- include_bin!("static/FiraSans-Regular.woff")));
+ include_bytes!("static/FiraSans-Regular.woff")));
try!(write(cx.dst.join("FiraSans-Medium.woff"),
- include_bin!("static/FiraSans-Medium.woff")));
+ include_bytes!("static/FiraSans-Medium.woff")));
try!(write(cx.dst.join("Heuristica-Italic.woff"),
- include_bin!("static/Heuristica-Italic.woff")));
+ include_bytes!("static/Heuristica-Italic.woff")));
try!(write(cx.dst.join("SourceSerifPro-Regular.woff"),
- include_bin!("static/SourceSerifPro-Regular.woff")));
+ include_bytes!("static/SourceSerifPro-Regular.woff")));
try!(write(cx.dst.join("SourceSerifPro-Bold.woff"),
- include_bin!("static/SourceSerifPro-Bold.woff")));
+ include_bytes!("static/SourceSerifPro-Bold.woff")));
try!(write(cx.dst.join("SourceCodePro-Regular.woff"),
- include_bin!("static/SourceCodePro-Regular.woff")));
+ include_bytes!("static/SourceCodePro-Regular.woff")));
try!(write(cx.dst.join("SourceCodePro-Semibold.woff"),
- include_bin!("static/SourceCodePro-Semibold.woff")));
+ include_bytes!("static/SourceCodePro-Semibold.woff")));
fn collect(path: &Path, krate: &str,
key: &str) -> io::IoResult<Vec<String>> {
/// # Example
///
/// ```rust,ignore
- /// let secret_key = include_bin!("secret-key.bin");
+ /// let secret_key = include_bytes!("secret-key.bin");
/// ```
#[macro_export]
- macro_rules! include_bin { ($file:expr) => ({ /* compiler built-in */ }) }
+ macro_rules! include_bytes { ($file:expr) => ({ /* compiler built-in */ }) }
+
+ /// Deprecated alias for `include_bytes!()`.
+ #[macro_export]
+ macro_rules! include_bin { ($file:expr) => ({ /* compiler built-in */}) }
/// Expands to a string that represents the current module path.
///
syntax_expanders.insert(intern("include_bin"),
builtin_normal_expander(
ext::source_util::expand_include_bin));
+ syntax_expanders.insert(intern("include_bytes"),
+ builtin_normal_expander(
+ ext::source_util::expand_include_bytes));
syntax_expanders.insert(intern("module_path"),
builtin_normal_expander(
ext::source_util::expand_mod));
pub fn expand_include_bin(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
-> Box<base::MacResult+'static> {
- let file = match get_single_str_from_tts(cx, sp, tts, "include_bin!") {
+ cx.span_warn(sp, "include_bin! is deprecated; use include_bytes! instead");
+ expand_include_bytes(cx, sp, tts)
+}
+
+pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
+ -> Box<base::MacResult+'static> {
+ let file = match get_single_str_from_tts(cx, sp, tts, "include_bytes!") {
Some(f) => f,
None => return DummyResult::expr(sp)
};
use std::io::{stdio, MemReader, BufferedReader};
let rdr = if os::getenv("RUST_BENCH").is_some() {
- let foo = include_bin!("shootout-k-nucleotide.data");
+ let foo = include_bytes!("shootout-k-nucleotide.data");
box MemReader::new(foo.to_vec()) as Box<Reader>
} else {
box stdio::stdin() as Box<Reader>
include_str!(invalid); //~ ERROR
include_str!("i'd be quite surprised if a file with this name existed"); //~ ERROR
- include_bin!(invalid); //~ ERROR
- include_bin!("i'd be quite surprised if a file with this name existed"); //~ ERROR
+ include_bytes!(invalid); //~ ERROR
+ include_bytes!("i'd be quite surprised if a file with this name existed"); //~ ERROR
trace_macros!(invalid); //~ ERROR
}
// except according to those terms.
pub static X: &'static str = "foobarbaz";
-pub static Y: &'static [u8] = include_bin!("lib.rs");
+pub static Y: &'static [u8] = include_bytes!("lib.rs");
trait Foo {}
impl Foo for uint {}
.as_slice()
.starts_with("/* this is for "));
assert!(
- include_bin!("syntax-extension-source-utils-files/includeme.fragment")
+ include_bytes!("syntax-extension-source-utils-files/includeme.fragment")
[1] == (42 as u8)); // '*'
// The Windows tests are wrapped in an extra module for some reason
assert!((m1::m2::where_am_i().as_slice().ends_with("m1::m2")));