From 9d757e8678e334e5a740ac750c76a9ed4e785cba Mon Sep 17 00:00:00 2001 From: Hernan Grecco Date: Sun, 3 Apr 2016 01:06:37 -0300 Subject: [PATCH] imp(macros.rs): Added write_nspaces macro (a new version of write_spaces) `write_nspaces` has three differences with `write_spaces` 1. Accepts arguments with attribute access (such as self.writer) 2. The order of the arguments is swapped to make the writer the first argument as in other write related macros. 3. Does not use the `write!` macro under the hood but rather calls directly `write` I have chosen to put the function under a new name to avoid backwards compatibility problem but it might be better to migrate everything to `write_nspaces` (and maybe rename it `write_spaces`) --- src/macros.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/macros.rs b/src/macros.rs index f7d50505..9abde7bd 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -586,6 +586,19 @@ macro_rules! write_spaces { }) } +// Helper/deduplication macro for printing the correct number of spaces in help messages +// used in: +// src/args/arg_builder/*.rs +// src/app/mod.rs +macro_rules! write_nspaces { + ($dst:expr, $num:expr) => ({ + debugln!("macro=write_spaces!;"); + for _ in 0..$num { + try!($dst.write(b" ")); + } + }) +} + // convenience macro for remove an item from a vec macro_rules! vec_remove { ($vec:expr, $to_rem:expr) => {