#format-string #string #fmt #format #macro

no-std reusable-fmt

Reusable format strings for format! and friends

4 releases

0.2.0 May 14, 2021
0.1.2 Apr 4, 2021
0.1.1 Apr 4, 2021
0.1.0 Apr 4, 2021

#46 in #fmt

Download history 23/week @ 2023-12-13 71/week @ 2023-12-20 27/week @ 2023-12-27 5/week @ 2024-01-03 9/week @ 2024-01-10 44/week @ 2024-01-17 22/week @ 2024-01-24 1/week @ 2024-01-31 1/week @ 2024-02-07 44/week @ 2024-02-14 100/week @ 2024-02-21 158/week @ 2024-02-28 148/week @ 2024-03-06 247/week @ 2024-03-13 143/week @ 2024-03-20 54/week @ 2024-03-27

596 downloads per month

WTFPL license

9KB
93 lines

reusable-fmt

RUST crates.io docs.rs

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.

Installation

Cargo.toml:

[dependencies]
reusable-fmt = { git = https://github.com/rupansh/reusable-fmt }

src.rs:

use reusable_fmt::*;

Example Usage

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!");
}

Why

  • Makes format strings less redundant
  • No runtime overhead! everything is compile time.
  • Dependency-free (unless you count build-dependencies)

Contribution

Feel free to request and implement features. I am not that good with macros so code improvements are welcome too!

Testing

Tests should be run on nightly

cargo +nightly test

Documentation

Documentation should be compiled on nightly

cargo +nightly doc

No runtime deps

~195KB