Crates.io | formatify |
lib.rs | formatify |
version | 0.2.0 |
source | src |
created_at | 2023-11-25 09:36:42.627011 |
updated_at | 2023-12-02 04:49:45.508772 |
description | formatify: A rust library specializing in dynamic runtime string formatting, ideal for applications requiring adaptable text representation. |
homepage | |
repository | https://github.com/chgroeling/formatify.git |
max_upload_size | |
id | 1048166 |
size | 54,045 |
Formatify is a Rust library tailored for flexible string formatting. It takes inspiration from Git's commit log formatting system (see here). This library provides robust tools to parse strings containing placeholders and replace them with appropriate values. It's an excellent choice for applications needing dynamic text representations.
Explore more in our documentation.
To get started with Formatify, here's a simple example:
use formatify::{Formatify, PlaceholderFormatter};
use std::collections::HashMap;
let mut key_value_pairs = HashMap::new();
key_value_pairs.insert("name", "Alice".into());
let formatter = Formatify::new();
let formatted_string = formatter.replace_placeholders(&key_value_pairs, "Hello, %(name)!");
assert_eq!(formatted_string, "Hello, Alice!");
In this example, we create a HashMap with key-value pairs, initialize Formatify, and replace the placeholder %(name)
with the corresponding value from the HashMap.
Formatify includes several helpful methods:
replace_placeholders
: Substitutes placeholders in a string with their corresponding values from a HashMap.measure_lengths
: Calculates the length of a string and the lengths of each placeholder it contains.extract_placeholder_keys
: Identifies and lists all the placeholders in a string.For detailed information on these methods, check out our module documentation.
Formatify is built to integrate smoothly into your existing Rust projects. It is compatible with standard Rust data types and collection frameworks.
Contributions are welcome! For bug reports, feature requests, or general feedback, please open an issue on the repository's issue tracker.