{"id":18004185,"url":"https://github.com/ivorforce/display-with-options","last_synced_at":"2025-07-20T12:35:40.215Z","repository":{"id":236121264,"uuid":"791957449","full_name":"Ivorforce/display-with-options","owner":"Ivorforce","description":"Display and Debug with options passed around. Indentation functionality.","archived":false,"fork":false,"pushed_at":"2024-04-26T11:37:27.000Z","size":24,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-30T01:44:20.359Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://crates.io/crates/display_with_options","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/Ivorforce.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.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":"2024-04-25T17:41:49.000Z","updated_at":"2024-04-26T11:37:30.000Z","dependencies_parsed_at":"2024-04-25T18:48:41.026Z","dependency_job_id":"937f2db2-6115-43c6-b429-08c4a78c76a6","html_url":"https://github.com/Ivorforce/display-with-options","commit_stats":null,"previous_names":["ivorforce/display-with-options"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ivorforce%2Fdisplay-with-options","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ivorforce%2Fdisplay-with-options/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ivorforce%2Fdisplay-with-options/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ivorforce%2Fdisplay-with-options/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ivorforce","download_url":"https://codeload.github.com/Ivorforce/display-with-options/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247157079,"owners_count":20893202,"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-30T00:13:36.540Z","updated_at":"2025-04-04T09:42:17.172Z","avatar_url":"https://github.com/Ivorforce.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# display_with_options\n\nThis tiny (\u003c 200 LOC) crate allows you to pass options around in Display and Debug.\n\nIt also adds a way to indent a formatter implicitly on fresh new lines.\n\nBoth components are technically separate, but interact in useful ways to provide a customizable\nindentation and pretty printing pipeline. In contrast to similar crates, this one gives you full\ncontrol while maintaining a close relationship with rust core functionality.\n\n## Usage Examples\n\n### IndentingFormatter\n\n```rust\nuse display_with_options::IndentingFormatter;\n\nfn main() {\n    let mut dst: Vec\u003cu8\u003e = vec![];\n    \n    writeln!(dst, \"A\").unwrap();\n    \n    let mut f = IndentingFormatter::new(\u0026mut dst, \"    \");\n    writeln!(f, \"B\").unwrap();\n}\n```\n\nResult:\n```\nA\n    B\n```\n\n### DisplayWithOptions\n\n```rust\nuse std::fmt::{Formatter, Write};\nuse display_with_options::{DisplayWithOptions, IndentingFormatter, IndentOptions, with_options};\n\n/// Tree-like structure\nstruct Node {\n    name: String,\n    children: Vec\u003cBox\u003cNode\u003e\u003e\n}\n\nimpl Node {\n    pub fn new(name: \u0026str, children: Vec\u003cBox\u003cNode\u003e\u003e) -\u003e Box\u003cNode\u003e {\n        Box::new(Node {\n            name: name.to_string(),\n            children\n        })\n    }\n}\n\nimpl\u003c'a\u003e DisplayWithOptions\u003cIndentOptions\u003c'a\u003e\u003e for Node {\n    fn fmt(\u0026self, f: \u0026mut Formatter, options: \u0026IndentOptions) -\u003e std::fmt::Result {\n        writeln!(f, \"{}{}\", options, self.name)?;\n\n        let options = options.deeper();\n        let mut f = IndentingFormatter::new(f, \u0026options.full_indentation);\n        let options = options.restart();\n\n        for child in self.children.iter() {\n            write!(f, \"{}\", with_options(child.as_ref(), \u0026options))?;\n        }\n\n        Ok(())\n    }\n}\n\n// Test the Code\n\nfn main() {\n    let tree = Node::new(\"A\", vec![\n        Node::new(\"B\", vec![\n            Node::new(\"C\", vec![]),\n        ]),\n        Node::new(\"D\", vec![]),\n    ]);\n\n    let options = IndentOptions::new(\"    \");\n    println!(\"{}\", with_options(tree.as_ref(), \u0026options));\n}\n```\n\nResult:\n```\nA\n    B\n        C\n    D\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivorforce%2Fdisplay-with-options","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fivorforce%2Fdisplay-with-options","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivorforce%2Fdisplay-with-options/lists"}