Crates.io | reusable-fmt |
lib.rs | reusable-fmt |
version | 0.2.0 |
source | src |
created_at | 2021-04-04 11:28:25.002668 |
updated_at | 2021-05-14 13:13:39.376118 |
description | Reusable format strings for format! and friends |
homepage | |
repository | https://github.com/rupansh/reusable-fmt |
max_upload_size | |
id | 378726 |
size | 14,417 |
Reusable format strings for std::fmt macros
Initial Release
This crate provides compile-time defined format string support for std::fmt
macros like write!
, print!
, format!
, etc.
Cargo.toml
:
[dependencies]
reusable-fmt = { git = https://github.com/rupansh/reusable-fmt }
src.rs
:
use reusable_fmt::*;
use reusable_fmt::*;
// This defines your format strings
fmt_reuse! {
TEST1 = "This is a test! {}";
TEST2 = "You can pass multiple format args! {} {}";
TEST3 = r#"Raw Strings work too!! {}"#;
TEST4 = "Named args {arg}";
TEST5 = "Positional args {1} {0}";
TEST6 = "Mixed {} {2} {1} {arg}";
}
fn main() {
prntln!(TEST1, "Hello World"); // This is a test! Hello World
let test = fmt!(TEST6, "Hello", "Test", "World", arg="Named"); // Mixed Hello World Test Named
prntln!("{}", "WOW This works too!");
}
Feel free to request and implement features. I am not that good with macros so code improvements are welcome too!
Tests should be run on nightly
cargo +nightly test
Documentation should be compiled on nightly
cargo +nightly doc