{"id":16819567,"url":"https://github.com/slowli/compile-fmt","last_synced_at":"2025-04-11T02:51:45.821Z","repository":{"id":196449478,"uuid":"696128385","full_name":"slowli/compile-fmt","owner":"slowli","description":"Compile-time formatting in Rust and derived functionality (e.g., panics / assertions)","archived":false,"fork":false,"pushed_at":"2023-12-28T08:35:38.000Z","size":1154,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-25T00:40:45.030Z","etag":null,"topics":["compile-time","constant","formatting"],"latest_commit_sha":null,"homepage":"","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/slowli.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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-09-25T06:30:53.000Z","updated_at":"2023-09-25T07:18:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"38d51286-c139-4cfa-afb9-b8f7396789b5","html_url":"https://github.com/slowli/compile-fmt","commit_stats":null,"previous_names":["slowli/compile-fmt"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slowli%2Fcompile-fmt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slowli%2Fcompile-fmt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slowli%2Fcompile-fmt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slowli%2Fcompile-fmt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/slowli","download_url":"https://codeload.github.com/slowli/compile-fmt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248333117,"owners_count":21086193,"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":["compile-time","constant","formatting"],"created_at":"2024-10-13T10:53:51.814Z","updated_at":"2025-04-11T02:51:45.791Z","avatar_url":"https://github.com/slowli.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Compile-Time Formatting\n\n[![Build Status](https://github.com/slowli/compile-fmt/workflows/CI/badge.svg?branch=main)](https://github.com/slowli/compile-fmt/actions)\n[![License: MIT OR Apache-2.0](https://img.shields.io/badge/License-MIT%2FApache--2.0-blue)](https://github.com/slowli/compile-fmt#license)\n![rust 1.65+ required](https://img.shields.io/badge/rust-1.65+-blue.svg?label=Required%20Rust)\n![no_std supported](https://img.shields.io/badge/no__std-tested-green.svg)\n\n**Documentation:**\n[![crate docs (main)](https://img.shields.io/badge/main-yellow.svg?label=docs)](https://slowli.github.io/compile-fmt/compile_fmt/)\n\nThis crate allows formatting values in compile time (e.g., in `const fn`s). The formatted values\nare not required to be constants; e.g., arguments or local vars in `const fn` can be formatted.\n\nFeatures:\n\n- Zero dependencies.\n- Unconditionally `#[no_std]`-compatible.\n- The formatting logic is space-efficient; i.e., it allocates the least amount of bytes\n  that can provably to be sufficient for all possible provided inputs.\n- Does not rely on proc macros. This makes the library more lightweight.\n\n## Why?\n\nA guiding use case for the crate is richer dynamic compile-time panic messages. It can be used\nin other contexts as well (including in runtime).\n\n## Usage\n\nAdd this to your `Crate.toml`:\n\n```toml\n[dependencies]\ncompile-fmt = \"0.1.0\"\n```\n\n### Basic usage\n\n```rust\nuse compile_fmt::{compile_assert, clip, fmt};\n\nconst fn check_str(s: \u0026str) {\n    const MAX_LEN: usize = 16;\n    compile_assert!(\n        s.len() \u003c= MAX_LEN,\n        \"String '\", s =\u003e clip(MAX_LEN, \"…\"), \"' is too long; \\\n         expected no more than \", MAX_LEN, \" bytes, got \",\n        s.len() =\u003e fmt::\u003cusize\u003e(), \" bytes\"\n    );\n    // ^ `clip` and `fmt` specify how dynamic (non-constant) args\n    // should be formatted\n  \n    // main logic\n}\n\nlet res = std::panic::catch_unwind(|| {\n    check_str(\"very long string indeed\");\n});\nlet err = res.unwrap_err();\nlet panic_message = err.downcast_ref::\u003cString\u003e().unwrap();\nassert_eq!(\n    panic_message,\n    \"String 'very long string…' is too long; expected no more than \\\n     16 bytes, got 23 bytes\"\n);\n```\n\nSee crate docs for more examples of usage.\n\n## Limitations\n\n- Only a few types from the standard library can be formatted: integers, `char`s and `str`ings.\n- Formatting specifiers do not support hex encoding, debug formatting etc.\n- Padding logic assumes that any Unicode char has identical displayed width, which isn't really\n  true (e.g., there are chars that have zero width and instead combine with the previous char).\n  The same assumption is made by the `std` padding logic.\n\n## Alternatives and similar tools\n\n- [`const_panic`] provides functionality covering the guiding use case (compile-time panics).\n  It supports more types and formats at the cost of being more complex. It also uses a different\n  approach to compute produced message sizes.\n- [`const_format`] provides general-purpose formatting of constant values. It doesn't seem to support\n  \"dynamic\" / non-constant args.\n\n## Contributing\n\nAll contributions are welcome! See [the contributing guide](CONTRIBUTING.md) to help\nyou get involved.\n\n## License\n\n`compile-fmt` is licensed under either of [Apache License, Version 2.0](LICENSE-APACHE)\nor [MIT license](LICENSE-MIT) at your option.\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in `compile-fmt` by you, as defined in the Apache-2.0 license,\nshall be dual licensed as above, without any additional terms or conditions.\n\n[`const_panic`]: https://crates.io/crates/const_panic\n[`const_format`]: https://crates.io/crates/const_format\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslowli%2Fcompile-fmt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fslowli%2Fcompile-fmt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslowli%2Fcompile-fmt/lists"}