|
1 |
| -# template |
| 1 | +# interpolator |
2 | 2 |
|
3 |
| -[](https://github.com/ModProg/template/actions/workflows/test.yaml) |
4 |
| -[](https://modprog.github.io/template/template/) |
5 |
| -<!-- [](https://crates.io/crates/template) --> |
6 |
| -<!-- [](https://docs.rs/template) --> |
| 3 | +[](https://github.com/ModProg/interpolator/actions/workflows/test.yaml) |
| 4 | +[](https://modprog.github.io/interpolator/interpolator/) |
| 5 | +[](https://crates.io/crates/interpolator) |
| 6 | +[](https://docs.rs/interpolator) |
| 7 | + |
| 8 | +Runtime implementation of `format!`. |
| 9 | + |
| 10 | +# `format` |
| 11 | +Runtime version of `format!`. |
| 12 | + |
| 13 | +Takes a string and a context, containing `Formattable` values, returns a |
| 14 | +string. |
| 15 | + |
| 16 | +```rs |
| 17 | +use template::{format, Formattable}; |
| 18 | + |
| 19 | +let formatted = format( |
| 20 | + "{value:+05}", // could be dynamic |
| 21 | + &[("value", Formattable::display(&12))].into_iter().collect(), |
| 22 | +) |
| 23 | +.unwrap(); |
| 24 | + |
| 25 | +assert_eq!(formatted, format!("{:+05}", 12)); |
| 26 | +``` |
| 27 | + |
| 28 | +# `write` |
| 29 | +Runtime version of `write!`. |
| 30 | + |
| 31 | +Takes a mutable `Write` e.g. `&mut String`, a format string and a context, |
| 32 | +containing `Formattable` values. |
| 33 | + |
| 34 | +```rs |
| 35 | +use template::{write, Formattable}; |
| 36 | + |
| 37 | +let mut buf = String::new(); |
| 38 | +write( |
| 39 | + &mut buf, |
| 40 | + "{value:+05}", // could be dynamic |
| 41 | + &[("value", Formattable::display(&12))].into_iter().collect(), |
| 42 | +) |
| 43 | +.unwrap(); |
| 44 | + |
| 45 | +assert_eq!(buf, format!("{:+05}", 12)); |
| 46 | +``` |
| 47 | + |
| 48 | +# Features |
| 49 | +By default only `Display` is supported, the rest of the |
| 50 | +[formatting traits](https://doc.rust-lang.org/std/fmt/index.html#formatting-traits) |
| 51 | +can be enabled through the following features. |
| 52 | + |
| 53 | +- `debug` enables `?`, `x?` and `X?` trait specifiers |
| 54 | +- `number` enables `x`, `X`, `b`, `o`, `e` and `E` trait specifiers |
| 55 | +- `pointer` enables `p` trait specifiers |
0 commit comments