{"id":17874233,"url":"https://github.com/modprog/interpolator","last_synced_at":"2025-03-21T22:31:49.340Z","repository":{"id":89278001,"uuid":"604869016","full_name":"ModProg/interpolator","owner":"ModProg","description":"runtime format strings, fully compatible with std's macros","archived":false,"fork":false,"pushed_at":"2023-04-17T21:10:34.000Z","size":152,"stargazers_count":5,"open_issues_count":4,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-18T05:43:58.660Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ModProg.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","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-02-22T00:36:22.000Z","updated_at":"2024-04-03T22:30:54.000Z","dependencies_parsed_at":"2024-10-28T11:37:47.523Z","dependency_job_id":"c350c4b0-4275-4ed3-9ff3-c7c23a5a1ca7","html_url":"https://github.com/ModProg/interpolator","commit_stats":{"total_commits":31,"total_committers":1,"mean_commits":31.0,"dds":0.0,"last_synced_commit":"3000bc114c12b8a4d7cc480e480e0e1af12dfcb8"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ModProg%2Finterpolator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ModProg%2Finterpolator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ModProg%2Finterpolator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ModProg%2Finterpolator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ModProg","download_url":"https://codeload.github.com/ModProg/interpolator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244880298,"owners_count":20525506,"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-10-28T11:08:07.931Z","updated_at":"2025-03-21T22:31:49.334Z","avatar_url":"https://github.com/ModProg.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# interpolator\n\n[![CI Status](https://github.com/ModProg/interpolator/actions/workflows/test.yaml/badge.svg)](https://github.com/ModProg/interpolator/actions/workflows/test.yaml)\n[![Documentation for `main`](https://img.shields.io/badge/docs-main-informational)](https://modprog.github.io/interpolator/interpolator/)\n[![Crates.io](https://img.shields.io/crates/v/interpolator)](https://crates.io/crates/interpolator)\n[![Docs.rs](https://img.shields.io/crates/v/interpolator?color=informational\u0026label=docs.rs)](https://docs.rs/interpolator)\n\nRuntime implementation of `format!`.\n\n# `format`\nRuntime version of `format!`.\n\nTakes a string and a context, containing `Formattable` values, returns a\nstring.\n\n```rs\nuse std::collections::HashMap;\nuse template::{format, Formattable};\n\nlet formatted = format(\n    \"{value:+05}\", // could be dynamic\n    \u0026[(\"value\", Formattable::display(\u002612))].into_iter().collect::\u003cHashMap\u003c_,_\u003e\u003e(),\n)\n.unwrap();\n\nassert_eq!(formatted, format!(\"{:+05}\", 12));\n```\n\n# `write`\nRuntime version of `write!`.\n\nTakes a mutable `Write` e.g. `\u0026mut String`, a format string and a context,\ncontaining `Formattable` values.\n                                                                            \n```rs\nuse std::collections::HashMap;\nuse template::{write, Formattable};\n                                                                            \nlet mut buf = String::new();\nwrite(\n    \u0026mut buf,\n    \"{value:+05}\", // could be dynamic\n    \u0026[(\"value\", Formattable::display(\u002612))].into_iter().collect::\u003cHashMap\u003c_,_\u003e\u003e(),\n)\n.unwrap();\n                                                                            \nassert_eq!(buf, format!(\"{:+05}\", 12));\n```\n\n# `i` iter format\n\nThe feature `iter` enables an additional format trait `i`, it allows to\nformat a list of values with a format string and an optional join\nexpression.\n\nThe syntax is `{list:i(the format string, '{}' is the array element)(the\njoin)}`, an empty join can also be omitted `{list:i({})}`. If join is omitted\nthe format string `{}` can be omitted as well `{list:i}`.\n\nShould you need to use `)` inside your format string or join, you can add `#`\nsimilar to rust's [raw string](https://doc.rust-lang.org/reference/tokens.html#raw-string-literals)\n(i.e. `#(({}))#`).\n\nIt is also possible to only iterate a sub-slice specified through a range\nbefore the format string, i.e. `{list:i1..4}`. For open ranges range\nbounds can also be omitted. To index from the end, you can use negative\nrange bounds.\n\nIt is also possible to index a single value by only specifying an `isize`\n`{list:i1}`.\n\n\nA `Formattable` implementing iter is created using `Formattable::iter`:\n\n```rs\n// HashMap macro\nuse collection_literals::hash;\nuse interpolator::{format, Formattable};\n// Needs to be a slice of references because `Formattable::display` expects a\n// reference\nlet items = [\u0026\"hello\", \u0026\"hi\", \u0026\"hey\"].map(Formattable::display);\nlet items = Formattable::iter(\u0026items);\nlet format_str = \"Greetings: {items:i..-1(`{it}`)(, )} and {items:i-1..(`{it}`)}\";\nassert_eq!(\n    format(format_str, \u0026hash!(\"items\" =\u003e items))?,\n    \"Greetings: `hello`, `hi` and `hey`\"\n);\n# return Ok::\u003c(), interpolator::Error\u003e(())\n```\n\n# Features\nBy default only `Display` is supported, the rest of the\n[formatting traits](https://doc.rust-lang.org/std/fmt/index.html#formatting-traits)\ncan be enabled through the following features.\n\n- `debug` enables `?`, `x?` and `X?` trait specifiers\n- `number` enables `x`, `X`, `b`, `o`, `e` and `E` trait specifiers\n- `pointer` enables `p` trait specifiers\n- `iter` enables `i` trait specifier\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmodprog%2Finterpolator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmodprog%2Finterpolator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmodprog%2Finterpolator/lists"}