[![Current crates.io release](https://img.shields.io/crates/v/mufmt)](https://crates.io/crates/mufmt)
[![Documentation](https://img.shields.io/badge/docs.rs-mufmt-66c2a5?labelColor=555555&logoColor=white&logo=data:image/svg+xml;base64, )](https://docs.rs/mufmt/)

# Mufmt
Mufmt is a minimal and extensible runtime formatting library.

Mufmt allows arbitrary types to define a formatting syntax and compiled template format.
Mufmt also provides a number of built-in formats, backed by data stored in collection types like `HashMap` or `Vec`.

Please read the [API docs](https://docs.rs/mufmt/) for more detail.

## Examples
Render a template using keys read from a `HashMap`
```rust
use mufmt::Template;

use std::collections::HashMap;

// The `Ast` is &str
let template = Template::<&str, &str>::compile("Hello {name}!").unwrap();
// The `Manifest` is `HashMap<str, str>`
let mfst = HashMap::from([("name", "John")]);

assert_eq!(template.render(&mfst).unwrap(), "Hello John!");
```
Render a template by indexing into a `Vec`.
```rust
use mufmt::Template;

let s = "Order: {1}".to_owned();

// The `Ast` is usize; also use a String to store the template text
// which unlinks the lifetime
let template = Template::<String, usize>::compile(&s).unwrap();

// we can drop the original template string
drop(s);

// The `Manifest` is `Vec<&str>`
let mut mfst = vec!["Grapes", "Apples"];
assert_eq!(template.render(&mfst).unwrap(), "Order: Apples");

// Render again, but with new data
mfst.clear();
mfst.push("Cheese");
mfst.push("Milk");
assert_eq!(template.render(&mfst).unwrap(), "Order: Milk");

// You can even change the type, as long as the `Ast` is the same
let new_mfst = vec![12, 5];
assert_eq!(template.render(&new_mfst).unwrap(), "Order: 5");
```
