├── .gitignore ├── src ├── lib.rs ├── utils.rs ├── error.rs ├── placeholder.rs ├── macros.rs ├── template.rs └── format_spec.rs ├── .github ├── FUNDING.yml └── workflows │ └── ci.yml ├── examples ├── simple.rs ├── struct.rs ├── language.rs └── advance.rs ├── Cargo.toml ├── LICENSE-MIT ├── CHANGELOG.md ├── README.md └── LICENSE-APACHE /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /Cargo.lock 3 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | mod error; 2 | mod format_spec; 3 | mod macros; 4 | mod placeholder; 5 | mod template; 6 | mod utils; 7 | 8 | pub use error::{Error, ErrorKind}; 9 | pub use template::Template; 10 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/displaying-a-sponsor-button-in-your-repository 2 | 3 | github: [clitic] 4 | buy_me_a_coffee: clitic 5 | -------------------------------------------------------------------------------- /examples/simple.rs: -------------------------------------------------------------------------------- 1 | use formatx::formatx; 2 | 3 | fn main() { 4 | let template = "{} {0:-^10} {percentage:.2}"; 5 | let text = formatx!(template, "world!", "hello", percentage = 99.9999); 6 | println!("{}", text.unwrap()); 7 | } 8 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | on: 4 | push: 5 | branches: "main" 6 | pull_request: 7 | branches: "main" 8 | 9 | env: 10 | CARGO_TERM_COLOR: always 11 | 12 | jobs: 13 | build: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v4 17 | - name: Build 18 | run: cargo build 19 | - name: Test 20 | run: cargo test 21 | -------------------------------------------------------------------------------- /examples/struct.rs: -------------------------------------------------------------------------------- 1 | use formatx::formatx; 2 | use std::fmt::Display; 3 | 4 | #[derive(Debug)] 5 | struct Foo { 6 | _bar: String, 7 | } 8 | 9 | impl Display for Foo { 10 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 11 | write!(f, "{:?}", self) 12 | } 13 | } 14 | 15 | fn main() { 16 | let foo = Foo { 17 | _bar: "foo-bar-struct".to_owned(), 18 | }; 19 | 20 | println!("{}", formatx!("{:#?}", foo).unwrap()); 21 | } 22 | -------------------------------------------------------------------------------- /examples/language.rs: -------------------------------------------------------------------------------- 1 | use formatx::formatx; 2 | 3 | fn message(language: &str, name: &str, number: i32) -> String { 4 | let s = match language { 5 | "french" => "Bonjour {}, le nombre est {}", 6 | "spanish" => "Hola {}, el numero es {}", 7 | _ => "Hi {}, the number is {}", 8 | }; 9 | formatx!(s, name, number).unwrap() 10 | } 11 | 12 | fn main() { 13 | println!("{}", message("french", "Léa", 1)); 14 | println!("{}", message("spanish", "Sofia", 2)); 15 | println!("{}", message("english", "Ashley", 3)); 16 | } 17 | -------------------------------------------------------------------------------- /examples/advance.rs: -------------------------------------------------------------------------------- 1 | use formatx::Template; 2 | 3 | fn main() { 4 | let mut template = "{percentage color=true:.2} => {percentage color=false:.0}%" 5 | .parse::