{"id":20410907,"url":"https://github.com/mintlu8/default-constructor","last_synced_at":"2025-04-12T16:06:18.301Z","repository":{"id":234008214,"uuid":"788116172","full_name":"mintlu8/default-constructor","owner":"mintlu8","description":"Macros for creating pseudo-dsls that constructs structs through default construction and field conversion.","archived":false,"fork":false,"pushed_at":"2024-06-08T12:49:21.000Z","size":25,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-06-12T16:37:05.522Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/mintlu8.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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":"2024-04-17T20:03:52.000Z","updated_at":"2024-07-30T23:07:14.432Z","dependencies_parsed_at":"2024-07-30T23:18:58.104Z","dependency_job_id":null,"html_url":"https://github.com/mintlu8/default-constructor","commit_stats":null,"previous_names":["mintlu8/default-constructor"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mintlu8%2Fdefault-constructor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mintlu8%2Fdefault-constructor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mintlu8%2Fdefault-constructor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mintlu8%2Fdefault-constructor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mintlu8","download_url":"https://codeload.github.com/mintlu8/default-constructor/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224737131,"owners_count":17361345,"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-11-15T05:49:01.436Z","updated_at":"2025-04-12T16:06:18.286Z","avatar_url":"https://github.com/mintlu8.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# default-constructor\n\nMacros for creating pseudo-dsls that constructs structs through\ndefault construction and field conversion.\n\n## Motivation\n\nThis crates is primary designed for `bevy` where constructing large bundles\nwith `..Default::default()` is common.\n\n## Syntax\n\nTake `construct!` that uses `Into`.\n\n```rust\nconstruct! {\n    Student {\n        name: \"Timmy\",\n        age: 10,\n        father: Parent {\n            name: \"Tommy\",\n            age: 42\n        }\n    }\n}\n```\n\nThis expands to\n\n```rust\nStudent {\n    name: Into::into(\"Timmy\"),\n    age: Into::into(10),\n    father: construct! {\n        Parent {\n            name: \"Tommy\",\n            age: 42\n        }\n    }\n    ..Default::default()\n}\n```\n\nThe macro is recursive on nested struct declarations,\nif the behavior is not desired, wrap nested structs in brackets.\n\n```rust\nconstruct! {\n    Student {\n        name: \"Timmy\",\n        age: 10,\n        father: { Parent {\n            name: \"Tommy\",\n            age: 42\n        }}\n    }\n}\n```\n\n## Tuple Construction\n\nTo create a tuple, concatenate multiple structs with comma.\n\n```rust\nconstruct! {\n    Student {\n        name: \"Timmy\",\n        age: 10,\n    },\n    Son::\u003c2\u003e {\n        of: \"Tommy\"\n    },\n    Age(16),\n}\n```\n\n## Meta Constructor\n\nThe meta constructor macro allows you to define your own macro with\ncustom configurations.\n\nSee documentation on `meta_default_constructor!` for details.\n\n## `InferInto`\n\nInferInto allows the user to bypass the orphan rule to create conversions.\n\nBy default we provide `i32` (integer literal) to all numeric types\nand `i64` -\u003e `f64` in addition to the standard `From` and `Into`.\n\nIf multiple conversion paths are found, the conversion will fail,\nthus failing the `infer_construct` macro.\n\n## ChangeLog\n\n* 0.4\n  * `meta_default_constructor` no longer takes a list of imports as the first argument.\n  * `meta_default_constructor` can now create tuples by chaining with comma.\n\n* 0.5\n\n  Made changes to fit `bevy 0.15`'s patterns.\n\n  * No longer treats `Ident` as `Ident::default()`.\n  * No longer treats snake case functions as structs.\n  * All non-struct patterns falls through the macro.\n\n## License\n\nLicense under either of\n\nApache License, Version 2.0 (LICENSE-APACHE or \u003chttp://www.apache.org/licenses/LICENSE-2.0\u003e)\nMIT license (LICENSE-MIT or \u003chttp://opensource.org/licenses/MIT\u003e)\nat your option.\n\n## Contribution\n\nContributions are welcome!\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmintlu8%2Fdefault-constructor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmintlu8%2Fdefault-constructor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmintlu8%2Fdefault-constructor/lists"}