#concat #line #comma #space #join

no-std concat-with

Extend the function of the concat! macro in std

10 releases

0.2.9 Nov 30, 2023
0.2.8 Nov 2, 2022
0.2.7 Mar 5, 2022
0.2.6 Apr 21, 2021
0.1.0 Jun 2, 2020

#292 in Rust patterns

Download history 4618/week @ 2023-11-03 5736/week @ 2023-11-10 7163/week @ 2023-11-17 6987/week @ 2023-11-24 5421/week @ 2023-12-01 7241/week @ 2023-12-08 5024/week @ 2023-12-15 2111/week @ 2023-12-22 2534/week @ 2023-12-29 4794/week @ 2024-01-05 5472/week @ 2024-01-12 7971/week @ 2024-01-19 6811/week @ 2024-01-26 3109/week @ 2024-02-02 5535/week @ 2024-02-09 5315/week @ 2024-02-16

21,920 downloads per month
Used in 34 crates (22 directly)

MIT license

14KB
180 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.

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

Prefixes and suffixes can also be added.

assert_eq!("Someone says: Hello.\nSomeone says: Nice to meet you!", concat_with::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.

#[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