{"id":21736371,"url":"https://github.com/kyza/inline_format","last_synced_at":"2025-10-16T04:41:26.573Z","repository":{"id":172962636,"uuid":"648851763","full_name":"Kyza/inline_format","owner":"Kyza","description":null,"archived":false,"fork":false,"pushed_at":"2023-08-23T07:11:35.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"trunk","last_synced_at":"2025-01-25T21:11:23.551Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kyza.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-03T01:59:48.000Z","updated_at":"2023-06-03T01:59:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"b6dff5ee-5176-4b00-80c9-82492d7cf1f2","html_url":"https://github.com/Kyza/inline_format","commit_stats":null,"previous_names":["kyza/inline_format"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kyza%2Finline_format","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kyza%2Finline_format/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kyza%2Finline_format/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kyza%2Finline_format/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kyza","download_url":"https://codeload.github.com/Kyza/inline_format/tar.gz/refs/heads/trunk","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244715147,"owners_count":20497976,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-26T05:18:30.443Z","updated_at":"2025-10-16T04:41:21.532Z","avatar_url":"https://github.com/Kyza.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# inline_format\r\n\r\n[\u003cimg src=\"https://img.shields.io/badge/github-Kyza/inline_format?style=for-the-badge\u0026color=555555\u0026labelColor=333333\u0026logo=github\" alt=\"GitHub Badge\" height=\"20\"/\u003e][GitHub Link] [\u003cimg src=\"https://img.shields.io/crates/v/inline_format.svg?style=for-the-badge\u0026color=fc8d62\u0026labelColor=333333\u0026logo=rust\" alt=\"crates.io Badge\" height=\"20\"/\u003e][crates.io Link] [\u003cimg src=\"https://img.shields.io/badge/docs.rs-inline_format?style=for-the-badge\u0026color=555555\u0026labelColor=333333\u0026logo=docs.rs\" alt=\"docs.rs Badge\" height=\"20\"/\u003e][docs.rs Link] [\u003cimg src=\"https://img.shields.io/github/actions/workflow/status/Kyza/inline_format/test.yml?branch=trunk\u0026style=for-the-badge\u0026labelColor=333333\" alt=\"Build Status Badge\" height=\"20\"/\u003e][Build Status Link]\r\n\r\n[GitHub Link]: https://github.com/Kyza/inline_format\r\n[crates.io Link]: https://crates.io/crates/inline_format\r\n[docs.rs Link]: https://docs.rs/inline_format\r\n[Build Status Link]: https://github.com/Kyza/inline_format/actions?query=branch%3Atrunk\r\n\r\nA more readable collection of string formatting macros.\r\n\r\n```rs\r\nuse inline_format::format;\r\n\r\nlet val = 2 + 2;\r\nassert_eq!(\r\n\tstd::format!(\"text {{}} {val:04} text {:o}\", 10 * 10),\r\n\t     format!(\"text {} \" val:04 \" text \" 10 * 10:o)\r\n);\r\n```\r\n\r\n## Features\r\n\r\n- [x] `format!` macro.\r\n- [x] `write!` macro.\r\n- [x] `writeln!` macro.\r\n- [x] `print!` macro.\r\n- [x] `println!` macro.\r\n- [x] `eprint!` macro.\r\n- [x] `eprintln!` macro.\r\n- [x] `format_args!` macro.\r\n- [x] Optional comma separation.\r\n- [x] Named parameters.\r\n\r\n## STD Problems\r\n\r\nThe format macros in this crate work almost the same as [the standard format macros](https://doc.rust-lang.org/std/fmt/index.html).\r\n\r\nThe std macros have inline identifiers, but lack support for expressions.\r\n\r\nYou end up needing to split up your expressions and the places they go in the string. And this pattern only gets worse when you add more arguments and mix identifiers and expressions.\r\n\r\nUnless you save expressions to variables, suddenly you need to count and keep track of which arguments go where and which formatting traits get applied.\r\n\r\nModifying those arguments might even lead to mistakes as well, especially when converting to and from inline with the string. `!(\"{val}\") -\u003e !(\"{}\", val)`.\r\n\r\nOne built in solution is using [named parameters](https://doc.rust-lang.org/std/fmt/index.html#named-parameters) which does improve the experience, but it still has the disadvantage of being after the string.\r\n\r\n## Usage\r\n\r\nThis crate solves all of that by moving the code to outside of the string, and removing the concept of separate arguments (aside from the `stream` target in `write!` and `writeln!`).\r\n\r\n```rs\r\n// Glob importing from it will cause a conflict with Rust's std prelude.\r\n// If you'd like a different name there's always `inline_format::{format as iformat}`.\r\nuse inline_format::format;\r\n\r\nlet val = 2 + 2;\r\nformat!(\"text {} \" val:04 \" text \" 10 * 10) // text {} 0004 text 100\r\n\r\n// Comma separation is optional.\r\n// All other examples will be without commas.\r\nformat!(\"text {} \", val:04, \" text \", 10 * 10) // text {} 0004 text 100\r\n```\r\n\r\nNow you can see exactly where your expressions are located in the string at a glance, and what formatting traits are applied to them if any. All by continuously reading left to right.\r\n\r\nOn top of that, there's no need to escape `{}` since there's no special syntax inside of the string anymore.\r\n\r\nSince the macros compile to the std macro equivalents, they should support the same things and do what you'd normally expect them to do.\r\n\r\n## More Examples\r\n\r\n### Joining two expressions.\r\n\r\nTo join multiple expressions in a row, put `\"\"` in between them.\r\n\r\n```rs\r\nformat!(2 + 2 \"\" 10 * 10 :04) // 40100\r\n```\r\n\r\n### Using blocks.\r\n\r\nIf you have a longer expression you might need to close it in a block.\r\n\r\n```rs\r\nformat!({\r\n\tlet val = 2 + 2;\r\n\tval\r\n} \"\" 10 * 10 :04) // 40100\r\n```\r\n\r\n### Using named parameters.\r\n\r\nIf you'd like to use an expression multiple times, you can name it and reference the name.\r\n\r\nFormat traits apply ***to the section not the variable***.\r\n\r\nBecause of how `format_args!` works the named parameters don't live long enough, so they get automatically cloned for you rather than evaluated multiple times.\r\n\r\n```rs\r\nformat!(x10 = 10 * 10:o \" \" x10) // 144 100\r\n\r\n// Named parameters can also be surrounded in blocks.\r\n// Format traits go outside the block.\r\nformat!({x10 = 10 * 10}:o \" \" x10) // 144 100\r\n```\r\n\r\n### Unbalanced fill character.\r\n\r\nRust's macro syntax *absolutely cannot* have unbalanced braces or quotes.\r\n\r\nThe following produces an error.\r\n\r\n```rs\r\nformat!(2:\"\u003c5)\r\n```\r\n\r\nIn order to fix this, wrap the traits in quotes and escape the character if it's a `\"`.\r\n\r\n```rs\r\nformat!(2:\"\\\"\u003c5\") // 2\"\"\"\"\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkyza%2Finline_format","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkyza%2Finline_format","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkyza%2Finline_format/lists"}