safe_format

Crates.iosafe_format
lib.rssafe_format
version0.1.5
sourcesrc
created_at2024-07-09 09:43:31.783264
updated_at2024-07-09 12:42:56.434857
descriptionsafe_format! macro works similarly to the built-in format! macro but allows for named parameters and it safely ignores any extra parameters that are not used in format string
homepagehttps://github.com/AllenDang/safe_format
repositoryhttps://github.com/AllenDang/safe_format
max_upload_size
id1296861
size18,250
Allen Dang (AllenDang)

documentation

README

safe_format

safe_format is a procedural macro for Rust that allows you to safely format strings with named parameters. It works similarly to the built-in format! macro but allows for named parameters, and it safely ignores any extra parameters that are not used in the format string.

Features

  • Named parameters for string formatting.
  • Ignores extra parameters that are not used in the format string.
  • Simple and intuitive API.

Usage

use safe_format::safe_format;

fn main() {
    let name = "Allen";
    let age = 19;
    let pattern = "Greeting from {name}";
    let greeting = safe_format!(pattern, name = name, age = age);
    println!("{}", greeting);  // Output: Greeting from Allen
}

Add Dependency

First, add the safe_format_macro crate as a dependency in your Cargo.toml:

[dependencies]
safe_format = 0.1
Commit count: 26

cargo fmt