{"id":13503073,"url":"https://github.com/dtolnay/indoc","last_synced_at":"2025-05-13T19:10:06.313Z","repository":{"id":5920278,"uuid":"54252316","full_name":"dtolnay/indoc","owner":"dtolnay","description":"Indented document literals for Rust","archived":false,"fork":false,"pushed_at":"2025-03-03T23:32:36.000Z","size":459,"stargazers_count":703,"open_issues_count":1,"forks_count":18,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-22T06:05:30.723Z","etag":null,"topics":["plugin","rust"],"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/dtolnay.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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,"zenodo":null},"funding":{"github":"dtolnay"}},"created_at":"2016-03-19T07:01:28.000Z","updated_at":"2025-04-07T17:39:51.000Z","dependencies_parsed_at":"2023-01-13T13:45:15.454Z","dependency_job_id":"b03fd9d6-25d0-4138-acfe-4fd3fac565ce","html_url":"https://github.com/dtolnay/indoc","commit_stats":{"total_commits":312,"total_committers":9,"mean_commits":"34.666666666666664","dds":0.03525641025641024,"last_synced_commit":"8304a10e23cc37caf1dd53c0aca31666ef4b5714"},"previous_names":[],"tags_count":49,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtolnay%2Findoc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtolnay%2Findoc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtolnay%2Findoc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dtolnay%2Findoc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dtolnay","download_url":"https://codeload.github.com/dtolnay/indoc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250871118,"owners_count":21500594,"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":["plugin","rust"],"created_at":"2024-07-31T22:02:35.810Z","updated_at":"2025-04-25T18:27:33.031Z","avatar_url":"https://github.com/dtolnay.png","language":"Rust","funding_links":["https://github.com/sponsors/dtolnay"],"categories":["Rust"],"sub_categories":[],"readme":"Indented Documents (indoc)\n==========================\n\n[\u003cimg alt=\"github\" src=\"https://img.shields.io/badge/github-dtolnay/indoc-8da0cb?style=for-the-badge\u0026labelColor=555555\u0026logo=github\" height=\"20\"\u003e](https://github.com/dtolnay/indoc)\n[\u003cimg alt=\"crates.io\" src=\"https://img.shields.io/crates/v/indoc.svg?style=for-the-badge\u0026color=fc8d62\u0026logo=rust\" height=\"20\"\u003e](https://crates.io/crates/indoc)\n[\u003cimg alt=\"docs.rs\" src=\"https://img.shields.io/badge/docs.rs-indoc-66c2a5?style=for-the-badge\u0026labelColor=555555\u0026logo=docs.rs\" height=\"20\"\u003e](https://docs.rs/indoc)\n[\u003cimg alt=\"build status\" src=\"https://img.shields.io/github/actions/workflow/status/dtolnay/indoc/ci.yml?branch=master\u0026style=for-the-badge\" height=\"20\"\u003e](https://github.com/dtolnay/indoc/actions?query=branch%3Amaster)\n\nThis crate provides a procedural macro for indented string literals. The\n`indoc!()` macro takes a multiline string literal and un-indents it at compile\ntime so the leftmost non-space character is in the first column.\n\n```toml\n[dependencies]\nindoc = \"2\"\n```\n\n*Compiler requirement: rustc 1.56 or greater.*\n\n\u003cbr\u003e\n\n## Using indoc\n\n```rust\nuse indoc::indoc;\n\nfn main() {\n    let testing = indoc! {\"\n        def hello():\n            print('Hello, world!')\n\n        hello()\n    \"};\n    let expected = \"def hello():\\n    print('Hello, world!')\\n\\nhello()\\n\";\n    assert_eq!(testing, expected);\n}\n```\n\nIndoc also works with raw string literals:\n\n```rust\nuse indoc::indoc;\n\nfn main() {\n    let testing = indoc! {r#\"\n        def hello():\n            print(\"Hello, world!\")\n\n        hello()\n    \"#};\n    let expected = \"def hello():\\n    print(\\\"Hello, world!\\\")\\n\\nhello()\\n\";\n    assert_eq!(testing, expected);\n}\n```\n\nAnd byte string literals:\n\n```rust\nuse indoc::indoc;\n\nfn main() {\n    let testing = indoc! {b\"\n        def hello():\n            print('Hello, world!')\n\n        hello()\n    \"};\n    let expected = b\"def hello():\\n    print('Hello, world!')\\n\\nhello()\\n\";\n    assert_eq!(testing[..], expected[..]);\n}\n```\n\n\u003cbr\u003e\n\n## Formatting macros\n\nThe indoc crate exports five additional macros to substitute conveniently for\nthe standard library's formatting macros:\n\n- `formatdoc!($fmt, ...)`\u0026ensp;\u0026mdash;\u0026ensp;equivalent to `format!(indoc!($fmt), ...)`\n- `printdoc!($fmt, ...)`\u0026ensp;\u0026mdash;\u0026ensp;equivalent to `print!(indoc!($fmt), ...)`\n- `eprintdoc!($fmt, ...)`\u0026ensp;\u0026mdash;\u0026ensp;equivalent to `eprint!(indoc!($fmt), ...)`\n- `writedoc!($dest, $fmt, ...)`\u0026ensp;\u0026mdash;\u0026ensp;equivalent to `write!($dest, indoc!($fmt), ...)`\n- `concatdoc!(...)`\u0026ensp;\u0026mdash;\u0026ensp;equivalent to `concat!(...)` with each string literal wrapped in `indoc!`\n\n```rust\nuse indoc::{concatdoc, printdoc};\n\nconst HELP: \u0026str = concatdoc! {\"\n    Usage: \", env!(\"CARGO_BIN_NAME\"), \" [options]\n\n    Options:\n        -h, --help\n\"};\n\nfn main() {\n    printdoc! {\"\n        GET {url}\n        Accept: {mime}\n        \",\n        url = \"http://localhost:8080\",\n        mime = \"application/json\",\n    }\n}\n```\n\n\u003cbr\u003e\n\n## Explanation\n\nThe following rules characterize the behavior of the `indoc!()` macro:\n\n1. Count the leading spaces of each line, ignoring the first line and any lines\n   that are empty or contain spaces only.\n2. Take the minimum.\n3. If the first line is empty i.e. the string begins with a newline, remove the\n   first line.\n4. Remove the computed number of spaces from the beginning of each line.\n\n\u003cbr\u003e\n\n## Unindent\n\nIndoc's indentation logic is available in the `unindent` crate. This may be\nuseful for processing strings that are not statically known at compile time.\n\nThe crate exposes two functions:\n\n- `unindent(\u0026str) -\u003e String`\n- `unindent_bytes(\u0026[u8]) -\u003e Vec\u003cu8\u003e`\n\n```rust\nuse unindent::unindent;\n\nfn main() {\n    let indented = \"\n            line one\n            line two\";\n    assert_eq!(\"line one\\nline two\", unindent(indented));\n}\n```\n\n\u003cbr\u003e\n\n#### License\n\n\u003csup\u003e\nLicensed under either of \u003ca href=\"LICENSE-APACHE\"\u003eApache License, Version\n2.0\u003c/a\u003e or \u003ca href=\"LICENSE-MIT\"\u003eMIT license\u003c/a\u003e at your option.\n\u003c/sup\u003e\n\n\u003cbr\u003e\n\n\u003csub\u003e\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in this crate by you, as defined in the Apache-2.0 license, shall\nbe dual licensed as above, without any additional terms or conditions.\n\u003c/sub\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdtolnay%2Findoc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdtolnay%2Findoc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdtolnay%2Findoc/lists"}