{"id":13648537,"url":"https://github.com/rodrimati1992/const_format_crates","last_synced_at":"2025-06-26T08:34:12.667Z","repository":{"id":37896934,"uuid":"288615034","full_name":"rodrimati1992/const_format_crates","owner":"rodrimati1992","description":"Compile-time string formatting","archived":false,"fork":false,"pushed_at":"2024-12-06T21:15:29.000Z","size":543,"stargazers_count":238,"open_issues_count":9,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-06-15T21:41:44.316Z","etag":null,"topics":["macros","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"zlib","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rodrimati1992.png","metadata":{"files":{"readme":"README.md","changelog":"Changelog.md","contributing":null,"funding":null,"license":"LICENSE-ZLIB.md","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":"2020-08-19T02:37:07.000Z","updated_at":"2025-06-14T02:05:42.000Z","dependencies_parsed_at":"2024-06-18T20:05:34.262Z","dependency_job_id":"4803b4f5-502e-4b47-9a54-a75457317bf9","html_url":"https://github.com/rodrimati1992/const_format_crates","commit_stats":{"total_commits":205,"total_committers":4,"mean_commits":51.25,"dds":"0.019512195121951237","last_synced_commit":"018e07dddf140ef0de9f7a0acf8aac9647042393"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/rodrimati1992/const_format_crates","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodrimati1992%2Fconst_format_crates","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodrimati1992%2Fconst_format_crates/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodrimati1992%2Fconst_format_crates/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodrimati1992%2Fconst_format_crates/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rodrimati1992","download_url":"https://codeload.github.com/rodrimati1992/const_format_crates/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodrimati1992%2Fconst_format_crates/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262030512,"owners_count":23247669,"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":["macros","rust"],"created_at":"2024-08-02T01:04:20.009Z","updated_at":"2025-06-26T08:34:12.645Z","avatar_url":"https://github.com/rodrimati1992.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"\n\n[![Rust](https://github.com/rodrimati1992/const_format_crates/workflows/Rust/badge.svg)](https://github.com/rodrimati1992/const_format_crates/actions)\n[![crates-io](https://img.shields.io/crates/v/const_format.svg)](https://crates.io/crates/const_format)\n[![api-docs](https://docs.rs/const_format/badge.svg)](https://docs.rs/const_format/*)\n\n\nCompile-time string formatting.\n\nThis crate provides types and macros for formatting strings at compile-time.\n\n# Rust versions\n\nThere are some features that require a variety of Rust versions,\nthe sections below describe the features that are available for each version.\n\n### Rust 1.57.0\n\nThese macros are available in Rust 1.57.0:\n\n- [`concatcp`]:\nConcatenates `integers`, `bool`, `char`, and `\u0026str` constants into a `\u0026'static str` constant.\n\n- [`formatcp`]:\n[`format`]-like formatting which takes `integers`, `bool`, `char`, and `\u0026str` constants,\nand emits a `\u0026'static str` constant.\n\n- [`str_get`]:\nIndexes a `\u0026'static str` constant, returning `None` when the index is out of bounds.\n\n- [`str_index`]:\nIndexes a `\u0026'static str` constant.\n\n- [`str_repeat`]:\nCreates a `\u0026'static str` by repeating a `\u0026'static str` constant `times` times.\n\n- [`str_splice`]:\nReplaces a substring in a `\u0026'static str` constant.\n\n- [`map_ascii_case`]:\nConverts a `\u0026'static str` constant to a different casing style,\ndetermined by a [`Case`] argument.\n\n- [`str_replace`]:\nReplaces all the instances of a pattern in a `\u0026'static str` constant with\nanother `\u0026'static str` constant.\n\n\nThe `\"assertcp\"` feature enables the [`assertcp`], [`assertcp_eq`],\nand [`assertcp_ne`] macros.\nThese macros are like the standard library assert macros,\nbut evaluated at compile-time,\nwith the limitation that they can only have primitive types as arguments\n(just like [`concatcp`] and [`formatcp`]).\n\n### Rust 1.64.0\n\nThe `\"rust_1_64\"` feature enables these macros:\n\n-  [`str_split`]: splits a string constant\n\n### Rust 1.83.0\n\nBy enabling the \"fmt\" feature, you can use a [`std::fmt`]-like API.\n\nThis requires Rust 1.83.0, because it uses mutable references in const fn.\n\nAll the other features of this crate are implemented on top of the [`const_format::fmt`] API:\n\n- [`concatc`]:\nConcatenates many standard library and user defined types into a `\u0026'static str` constant.\n\n- [`formatc`]:\n[`format`]-like macro that can format many standard library and user defined types into\na `\u0026'static str` constant.\n\n- [`writec`]:\n[`write`]-like macro that can format many standard library and user defined types\ninto a type that implements [`WriteMarker`].\n\nThe `\"derive\"` feature enables the [`ConstDebug`] macro,\nand the `\"fmt\"` feature.\u003cbr\u003e\n[`ConstDebug`] derives the [`FormatMarker`] trait,\nand implements an inherent `const_debug_fmt` method for compile-time debug formatting.\n\nThe `\"assertc\"` feature enables the [`assertc`], [`assertc_eq`], [`assertc_ne`] macros,\nand the `\"fmt\"` feature.\u003cbr\u003e\nThese macros are like the standard library assert macros, but evaluated at compile-time.\n\n# Examples\n\n### Concatenation of primitive types\n\n```rust\nuse const_format::concatcp;\n\nconst NAME: \u0026str = \"Bob\";\nconst FOO: \u0026str = concatcp!(NAME, \", age \", 21u8,\"!\");\n\nassert_eq!(FOO, \"Bob, age 21!\");\n```\n\n### Formatting primitive types\n\n```rust\nuse const_format::formatcp;\n\nconst NAME: \u0026str = \"John\";\n\nconst FOO: \u0026str = formatcp!(\"{NAME}, age {}!\", compute_age(NAME));\n\nassert_eq!(FOO, \"John, age 24!\");\n\nconst fn compute_age(s: \u0026str) -\u003e usize { s.len() * 6 }\n```\n\n### Formatting custom types\n\nThis example demonstrates how you can use the [`ConstDebug`] derive macro,\nand then format the type into a `\u0026'static str` constant.\n\nThis example requires Rust 1.83.0, and the `\"derive\"` feature.\n\n```rust\nuse const_format::{ConstDebug, formatc};\n\n#[derive(ConstDebug)]\nstruct Message{\n    ip: [Octet; 4],\n    value: \u0026'static str,\n}\n\n#[derive(ConstDebug)]\nstruct Octet(u8);\n\nconst MSG: Message = Message{\n    ip: [Octet(127), Octet(0), Octet(0), Octet(1)],\n    value: \"Hello, World!\",\n};\n\nconst FOO: \u0026str = formatc!(\"{:?}\", MSG);\n\nassert_eq!(\n    FOO,\n    \"Message { ip: [Octet(127), Octet(0), Octet(0), Octet(1)], value: \\\"Hello, World!\\\" }\"\n);\n\n```\n\n### Formatted const assertions\n\nThis example demonstrates how you can use the [`assertcp_ne`] macro to\ndo compile-time inequality assertions with formatted error messages.\n\nThis requires the `\"assertcp\"` feature.\n\n```rust, compile_fail\nuse const_format::assertcp_ne;\n\nmacro_rules! check_valid_pizza{\n    ($user:expr, $topping:expr) =\u003e {\n        assertcp_ne!(\n            $topping,\n            \"pineapple\",\n            \"You can't put pineapple on pizza, {}\",\n            $user,\n        );\n    }\n}\n\ncheck_valid_pizza!(\"John\", \"salami\");\ncheck_valid_pizza!(\"Dave\", \"sausage\");\ncheck_valid_pizza!(\"Bob\", \"pineapple\");\n\n```\n\nThis is the compiler output:\n\n```text\nerror[E0080]: evaluation of constant value failed\n  --\u003e src/lib.rs:178:27\n   |\n20 | check_valid_pizza!(\"Bob\", \"pineapple\");\n   |                           ^^^^^^^^^^^ the evaluated program panicked at '\nassertion failed: `(left != right)`\n left: `\"pineapple\"`\nright: `\"pineapple\"`\nYou can't put pineapple on pizza, Bob\n', src/lib.rs:20:27\n\n\n```\n\n\u003cdiv id=\"macro-limitations\"\u003e\u003c/div\u003e\n\n# Limitations\n\nAll of the macros from `const_format` have these limitations:\n\n- The formatting macros that expand to\n`\u0026'static str`s can only use constants from concrete types,\nso while a `Type::\u003cu8\u003e::FOO` argument would be fine,\n`Type::\u003cT\u003e::FOO` would not be (`T` being a type parameter).\n\n- Integer arguments must have a type inferrable from context,\n[more details in the Integer arguments section](#integer-args).\n\n- They cannot be used places that take string literals.\nSo `#[doc = \"foobar\"]` cannot be replaced with `#[doc = concatcp!(\"foo\", \"bar\") ]`.\n\n\u003cspan id=\"integer-args\"\u003e\u003c/span\u003e\n\n### Integer arguments\n\nInteger arguments must have a type inferrable from context.\nso if you only pass an integer literal it must have a suffix.\n\nExample of what does compile:\n\n```rust\nconst N: u32 = 1;\nassert_eq!(const_format::concatcp!(N + 1, 2 + N), \"23\");\n\nassert_eq!(const_format::concatcp!(2u32, 2 + 1u8, 3u8 + 1), \"234\");\n```\n\nExample of what does not compile:\n```rust,compile_fail\nassert_eq!(const_format::concatcp!(1 + 1, 2 + 1), \"23\");\n```\n# Plans\n\nNone right now.\n\n# Renaming crate\n\nAll function-like macros from `const_format` can be used when the crate is renamed.\n\nThe [`ConstDebug`] derive macro has the `#[cdeb(crate = \"foo::bar\")]` attribute to\ntell it where to find the `const_format` crate.\n\nExample of renaming the `const_format` crate in the Cargo.toml file:\n```toml\n[dependencies]\ncfmt = {version = \"0.*\", package = \"const_format\"}\n```\n\n# Cargo features\n\n- `\"fmt\"`: Enables the [`std::fmt`]-like API and `\"rust_1_83\"` feature,\nrequires Rust 1.83.0 because it uses mutable references in const fn.\u003cbr\u003e\nThis feature includes the [`formatc`]/[`writec`] formatting macros.\n\n- `\"derive\"`: requires Rust 1.83.0, implies the `\"fmt\"` feature,\nprovides the [`ConstDebug`] derive macro to format user-defined types at compile-time.\u003cbr\u003e\nThis implicitly uses the `syn` crate, so clean compiles take a bit longer than without the feature.\n\n- `\"assertc\"`: requires Rust 1.83.0, implies the `\"fmt\"` feature,\nenables the [`assertc`], [`assertc_eq`], and [`assertc_ne`] assertion macros.\u003cbr\u003e\nThis feature was previously named `\"assert\"`,\nbut it was renamed to avoid confusion with the `\"assertcp\"` feature.\n\n- `\"assertcp\"`:\nEnables the [`assertcp`], [`assertcp_eq`], and [`assertcp_ne`] assertion macros.\n\n- `\"rust_1_64\"`: Enables the [`str_split`] macro.\nAllows the `as_bytes_alt` methods and `slice_up_to_len_alt` methods to run\nin constant time, rather than linear time (proportional to the truncated part of the slice).\n\n- `\"rust_1_83\"`: Enables the `\"rust_1_64\"` feature\nand makes macros that evaluate to a value compatible with [inline const patterns].\n\n# No-std support\n\n`const_format` is unconditionally `#![no_std]`, it can be used anywhere Rust can be used.\n\n# Minimum Supported Rust Version\n\n`const_format` requires Rust 1.57.0.\n\nFeatures that require newer versions of Rust, or the nightly compiler,\nneed to be explicitly enabled with cargo features.\n\n[`assertc`]: https://docs.rs/const_format/0.2.*/const_format/macro.assertc.html\n\n[`assertc_eq`]: https://docs.rs/const_format/0.2.*/const_format/macro.assertc_eq.html\n\n[`assertc_ne`]: https://docs.rs/const_format/0.2.*/const_format/macro.assertc_ne.html\n\n[`assertcp`]: https://docs.rs/const_format/0.2.*/const_format/macro.assertcp.html\n\n[`assertcp_eq`]: https://docs.rs/const_format/0.2.*/const_format/macro.assertcp_eq.html\n\n[`assertcp_ne`]: https://docs.rs/const_format/0.2.*/const_format/macro.assertcp_ne.html\n\n[`concatcp`]: https://docs.rs/const_format/0.2.*/const_format/macro.concatcp.html\n\n[`formatcp`]: https://docs.rs/const_format/0.2.*/const_format/macro.formatcp.html\n\n[`format`]: https://doc.rust-lang.org/std/macro.format.html\n\n[`std::fmt`]: https://doc.rust-lang.org/std/fmt/index.html\n\n[`const_format::fmt`]: https://docs.rs/const_format/0.2.*/const_format/fmt/index.html\n\n[`concatc`]: https://docs.rs/const_format/0.2.*/const_format/macro.concatc.html\n\n[`formatc`]: https://docs.rs/const_format/0.2.*/const_format/macro.formatc.html\n\n[`writec`]: https://docs.rs/const_format/0.2.*/const_format/macro.writec.html\n\n[`write`]: https://doc.rust-lang.org/std/macro.write.html\n\n[`Formatter`]: https://docs.rs/const_format/0.2.*/const_format/fmt/struct.Formatter.html\n\n[`StrWriter`]: https://docs.rs/const_format/0.2.*/const_format/fmt/struct.StrWriter.html\n\n[`ConstDebug`]: https://docs.rs/const_format/0.2.*/const_format/derive.ConstDebug.html\n\n[`FormatMarker`]: https://docs.rs/const_format/0.2.*/const_format/marker_traits/trait.FormatMarker.html\n\n[`WriteMarker`]: https://docs.rs/const_format/0.2.*/const_format/marker_traits/trait.WriteMarker.html\n\n[`map_ascii_case`]: https://docs.rs/const_format/0.2.*/const_format/macro.map_ascii_case.html\n\n[`Case`]: https://docs.rs/const_format/0.2.*/const_format/enum.Case.html\n\n[`str_get`]: https://docs.rs/const_format/0.2.*/const_format/macro.str_get.html\n\n[`str_index`]: https://docs.rs/const_format/0.2.*/const_format/macro.str_index.html\n\n[`str_repeat`]: https://docs.rs/const_format/0.2.*/const_format/macro.str_repeat.html\n\n[`str_splice`]: https://docs.rs/const_format/0.2.*/const_format/macro.str_splice.html\n\n[`str_replace`]: https://docs.rs/const_format/0.2.*/const_format/macro.str_replace.html\n\n[`str_split`]: https://docs.rs/const_format/0.2.*/const_format/macro.str_split.html\n\n[`str::replace`]: https://doc.rust-lang.org/std/primitive.str.html#method.replace\n\n[inline const patterns]: https://doc.rust-lang.org/1.83.0/unstable-book/language-features/inline-const-pat.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frodrimati1992%2Fconst_format_crates","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frodrimati1992%2Fconst_format_crates","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frodrimati1992%2Fconst_format_crates/lists"}