Skip to content

Commit

Permalink
imp(macros.rs): Added write_nspaces macro (a new version of write_spa…
Browse files Browse the repository at this point in the history
…ces)

`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`)
  • Loading branch information
hgrecco committed Apr 13, 2016
1 parent 65b3f66 commit 9d757e8
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/macros.rs
Expand Up @@ -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) => {
Expand Down

0 comments on commit 9d757e8

Please sign in to comment.