#concat #line #comma #space #join

concat-with

Extend the function of the concat! macro in std

7 releases

0.2.6 Apr 21, 2021
0.2.5 Jul 29, 2020
0.2.4 Jun 27, 2020
0.1.0 Jun 2, 2020

#141 in Rust patterns

Download history 2155/week @ 2021-08-10 1725/week @ 2021-08-17 1365/week @ 2021-08-24 1237/week @ 2021-08-31 1321/week @ 2021-09-07 2542/week @ 2021-09-14 3012/week @ 2021-09-21 2767/week @ 2021-09-28 2582/week @ 2021-10-05 3115/week @ 2021-10-12 2732/week @ 2021-10-19 339/week @ 2021-10-26 525/week @ 2021-11-02 550/week @ 2021-11-09 421/week @ 2021-11-16 300/week @ 2021-11-23

1,826 downloads per month
Used in 20 crates (13 directly)

MIT license

13KB
179 lines

Concat With

CI

While the concat! macro in std is useful to create a static string slice (&'static str) from literals, it cannot set a separator for those. This crate therefore provides another concat! macro to deal with that situation.

#[macro_use] extern crate concat_with;

assert_eq!("test10btrue", concat!("test", 10, 'b', true));
assert_eq!("test, 10, b, true", concat!(with ", ", "test", 10, 'b', true));
assert_eq!("test\n10\nb\ntrue", concat_line!("test", 10, 'b', true));

Prefixes and suffixes can also be added.

#[macro_use] extern crate concat_with;

assert_eq!("Someone says: Hello.\nSomeone says: Nice to meet you!", concat_line!(prefix "Someone says: ", "Hello.", "Nice to meet you!"));

Create Your Own Macros

The concat_impl! macro can be used to create your own macros like concat_line! which concatenates literals separated by a specific literal.

extern crate concat_with;

#[doc(hidden)]
pub use concat_with::{concat, concat_impl}; // re-export `concat!` and `concat_impl!` if your custom macros use `#[macro_export]`

concat_impl! {
    #[macro_export]
    /// Concatenates literals into a static string slice separated by a comma and a whitespace, `, `. Prefixes and suffixes can also be added.
    concat_with_comma => ", ",
    #[macro_export]
    /// Concatenates literals into a static string slice separated by a colon, `:`. Prefixes and suffixes can also be added.
    concat_with_colon => ':',
}

assert_eq!("test, 10, b, true", concat_with_comma!("test", 10, 'b', true));
assert_eq!("test:10:b:true", concat_with_colon!("test", 10, 'b', true));

Crates.io

https://crates.io/crates/concat-with

Documentation

https://docs.rs/concat-with

License

MIT

No runtime deps