{"id":24555817,"url":"https://github.com/crambl/descriptive_toml_derive","last_synced_at":"2025-08-25T01:36:06.252Z","repository":{"id":181381002,"uuid":"666689578","full_name":"CramBL/descriptive_toml_derive","owner":"CramBL","description":"Procedural derive macro for serializing a struct into a TOML template with field descriptions that is easily edited and deserialized.","archived":false,"fork":false,"pushed_at":"2024-02-18T12:18:42.000Z","size":19,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-20T04:18:15.909Z","etag":null,"topics":["derive-macro","macros-rust","procedural-macro"],"latest_commit_sha":null,"homepage":"","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/CramBL.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2023-07-15T08:44:15.000Z","updated_at":"2023-07-25T18:09:21.000Z","dependencies_parsed_at":"2024-02-18T13:27:47.351Z","dependency_job_id":"f0dce484-de10-4d70-b8e3-5f1a32e1744c","html_url":"https://github.com/CramBL/descriptive_toml_derive","commit_stats":null,"previous_names":["crambl/descriptive_toml_derive"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/CramBL/descriptive_toml_derive","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CramBL%2Fdescriptive_toml_derive","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CramBL%2Fdescriptive_toml_derive/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CramBL%2Fdescriptive_toml_derive/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CramBL%2Fdescriptive_toml_derive/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CramBL","download_url":"https://codeload.github.com/CramBL/descriptive_toml_derive/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CramBL%2Fdescriptive_toml_derive/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271930745,"owners_count":24845472,"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","status":"online","status_checked_at":"2025-08-24T02:00:11.135Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["derive-macro","macros-rust","procedural-macro"],"created_at":"2025-01-23T04:32:43.530Z","updated_at":"2025-08-25T01:36:06.184Z","avatar_url":"https://github.com/CramBL.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Crates.io](https://img.shields.io/crates/d/descriptive_toml_derive)\n![GitHub commit activity (branch)](https://img.shields.io/github/commit-activity/m/crambl/descriptive_toml_derive)\n\n# Description\nProcedural derive macro for serializing a struct into a TOML template with field descriptions that is easily edited and deserialized.\n\nNested structs are not currently supported.\n\n# Purpose\nMake it easy to write a struct that defines a `TOML` template for optional configuration of an executable. Once the struct is deserialized with the derive macro implemented `to_string_pretty_toml()` function, it can be written to a (TOML) file, the file should be understandable without knowing any details of the binary. Deserializing the produced TOML file with no edits produceses the original struct with all optional fields `None`. Editing the produced TOML file will then deserialize into the original struct with those edited values.\n\n# Table of Contents\n- [Description](#description)\n- [Purpose](#purpose)\n- [Table of Contents](#table-of-contents)\n- [Guide](#guide)\n  - [What is derived?](#what-is-derived)\n  - [Example use in fastPASTA](#example-use-in-fastpasta)\n    - [Implementing](#implementing)\n    - [Serializing](#serializing)\n    - [Deserializing](#deserializing)\n\n# Guide\n\n## What is derived?\nA `pub trait` named `TomlConfig` with a single function with the signature:  `fn to_string_pretty_toml(\u0026self) -\u003e String`\n\n```rust\npub trait TomlConfig {\n    fn to_string_pretty_toml(\u0026self) -\u003e String;\n}\n```\n\n## Example use in fastPASTA\nThis macro was originally made for use in the [fastPASTA](https://crates.io/crates/fastpasta) crate.\nThe example is based on how the macro is used in `fastPASTA`.\n\n### Implementing\nThe struct `CustomChecks` is implemented like this:\n\n```rust\nuse descriptive_toml_derive::TomlConfig;\nuse serde_derive::{Deserialize, Serialize};\n\npub trait TomlConfig {\n    fn to_string_pretty_toml(\u0026self) -\u003e String;\n}\n\n// Deriving the `TomlConfig` macro which implements the `TomlConfig` trait.\n#[derive(TomlConfig, Default, Debug, Clone, PartialEq, Serialize, Deserialize)]\npub struct CustomChecks {\n    // Use the `description` field attribute of the macro\n    #[description = \"Number of CRU Data Packets expected in the data\"]\n    // Use the `example` field attribute of the macro to show some example values\n    #[example = \"20, 500532\"]\n    cdps: Option\u003cu32\u003e,\n\n    #[description = \"Number of Physics (PhT) Triggers expected in the data\"]\n    #[example = \"0, 10\"]\n    triggers_pht: Option\u003cu32\u003e,\n\n    #[description = \"Legal Chip ordering for Outer Barrel (ML/OL). Needs to be a list of two lists of 7 chip IDs\"]\n    #[example = \"[[0, 1, 2, 3, 4, 5, 6], [8, 9, 10, 11, 12, 13, 14]]\"]\n    chip_orders_ob: Option\u003c(Vec\u003cu8\u003e, Vec\u003cu8\u003e)\u003e,\n}\n```\n### Serializing\n\nThe template file is generated e.g. like this.\n```rust\nlet toml = CustomChecks::default().to_string_pretty_toml();\nstd::fs::write(\"custom_checks.toml\", toml).unwrap();\n```\nThe contents of \"custom_checks.toml\" is now:\n```toml\n# Number of CRU Data Packets expected in the data\n# Example: 20, 500532\n#cdps = None [ u32 ] # (Uncomment and set to enable this check)\n\n# Number of Physics (PhT) Triggers expected in the data\n# Example: 0, 10\n#triggers_pht = None [ u32 ] # (Uncomment and set to enable this check)\n\n# Legal Chip ordering for Outer Barrel (ML/OL). Needs to be a list of two lists of 7 chip IDs\n# Example: [[0, 1, 2, 3, 4, 5, 6], [8, 9, 10, 11, 12, 13, 14]]\n#chip_orders_ob = None [ (Vec \u003c u8 \u003e, Vec \u003c u8 \u003e) ] # (Uncomment and set to enable this check)\n```\nEditing all the fields to contain `Some` values could look like this:\n```toml\n# Number of CRU Data Packets expected in the data\n# Example: 20, 500532\ncdps = 20\n\n# Number of Physics (PhT) Triggers expected in the data\n# Example: 0, 10\ntriggers_pht = 0\n\n# Legal Chip ordering for Outer Barrel (ML/OL). Needs to be a list of two lists of 7 chip IDs\n# Example: [[0, 1, 2, 3, 4, 5, 6], [8, 9, 10, 11, 12, 13, 14]]\nchip_orders_ob = [[0, 1, 2, 3, 4, 5, 6], [8, 9, 10, 11, 12, 13, 14]]\n```\n### Deserializing\n\nDeserializing from a TOML file is the same method as with any other TOML file, using `serde_derive`:\n```rust\nlet toml = std::fs::read_to_string(\"custom_checks.toml\").unwrap();\nlet custom_checks = toml::from_str(\u0026toml).unwrap();\n```\n\nA user that is already familiar with the configuration file might simply write\n```toml\ncdps = 10\n```\nAnd input it to the binary. Which would deserialize into a struct with the `cdps` field containing `Some(10)`, and the rest of the fields are `None`.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrambl%2Fdescriptive_toml_derive","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrambl%2Fdescriptive_toml_derive","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrambl%2Fdescriptive_toml_derive/lists"}