echo/lib.rs
1//! Macro `echo!` and `echon!` print values separated by spaces without the
2//! need to specify `"{}"` format strings, similar to Linux `echo` and
3//! `echo -n` commands.
4//!
5//! To use the macro, you'll need to include the following declarations
6//! at the top level of your crate:
7//!
8//! ```ignore
9//! #![feature(phase)]
10//! #[phase(plugin)] extern crate echo;
11//! ```
12//!
13//! Then you can invoke it as follows:
14//!
15//! ```ignore
16//! let a = 0u;
17//! let b = vec![2i, 4, 6];
18//! // 0 [2, 4, 6] true
19//! echo!(a, b, true);
20//! // 0 (without newline)
21//! echon!(a);
22//! ```
23#![feature(macro_rules)]
24
25#[macro_export]
26/// Print space-separated values with newline
27macro_rules! echo {
28 ($($arg:tt)*) => ({
29 echon!($($arg)*)
30 println!("")
31 });
32}
33
34#[macro_export]
35/// Print space-separated values without newline
36macro_rules! echon {
37 ($head:expr $(, $tail:expr)*) => ({
38 print!("{}", $head);
39 $(print!(" {}", $tail);)*
40 });
41}