{"id":17874276,"url":"https://github.com/modprog/non-exhaustive","last_synced_at":"2025-07-06T14:36:20.069Z","repository":{"id":224209144,"uuid":"762732945","full_name":"ModProg/non-exhaustive","owner":"ModProg","description":null,"archived":false,"fork":false,"pushed_at":"2024-02-25T23:10:16.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-08T14:22:22.460Z","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/ModProg.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-02-24T14:42:53.000Z","updated_at":"2024-02-24T14:43:02.000Z","dependencies_parsed_at":"2024-02-24T14:46:42.270Z","dependency_job_id":"f2852df8-668f-459f-82a7-a8809541b7e4","html_url":"https://github.com/ModProg/non-exhaustive","commit_stats":null,"previous_names":["modprog/non-exhaustive"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ModProg%2Fnon-exhaustive","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ModProg%2Fnon-exhaustive/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ModProg%2Fnon-exhaustive/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ModProg%2Fnon-exhaustive/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ModProg","download_url":"https://codeload.github.com/ModProg/non-exhaustive/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246911467,"owners_count":20853657,"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-28T11:08:18.051Z","updated_at":"2025-04-03T00:13:04.924Z","avatar_url":"https://github.com/ModProg.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# non-exhaustive\n\n[![CI Status](https://github.com/ModProg/non-exhaustive/actions/workflows/test.yaml/badge.svg)](https://github.com/ModProg/non-exhaustive/actions/workflows/test.yaml)\n[![Crates.io](https://img.shields.io/crates/v/non-exhaustive)](https://crates.io/crates/non-exhaustive)\n[![Docs.rs](https://img.shields.io/crates/v/template?color=informational\u0026label=docs.rs)](https://docs.rs/non-exhaustive)\n[![Documentation for `main`](https://img.shields.io/badge/docs-main-informational)](https://modprog.github.io/non-exhaustive/non_exhaustive/)\n\nMacro to create non_exhaustive structs and structs with private fields with the [functional update syntax](https://doc.rust-lang.org/reference/expressions/struct-expr.html#functional-update-syntax), i.e., using `..Default::default()`.\n\nGiven the foreign structs:\n```rust\n#[non_exhaustive]\n#[derive(Default)]\npub struct NonExhaustive {\n  pub field: usize\n}\n\n#[derive(Default)]\npub struct PrivateFields {\n  pub pub_field: usize,\n  private_field: usize\n}\n```\n\nThe following is not possible:\n```rust\nNonExhaustive {\n  field: 1,\n  ..Default::default()\n};\n\nPrivateFields {\n  pub_field: 1,\n  ..Default::default()\n};\n```\n\n[`non_exhaustive!`] remedies that:\n```rust\nuse non_exhaustive::non_exhaustive;\n# mod module {#[derive(Default)] pub struct NonExhaustive {pub field: usize, _hack: usize} #[derive(Default)] pub struct PrivateFields { pub pub_field: usize, private_field: usize}} use module::*;\n\nnon_exhaustive! {NonExhaustive {\n  field: 1,\n  ..Default::default()\n}};\n\nnon_exhaustive! {PrivateFields {\n  pub_field: 1,\n  ..Default::default()\n}};\n```\n\nFor the common case of using [`Default::default()`], [`non_exhaustive!`] allows omitting the `..expression`:\n\n```rust\nuse non_exhaustive::non_exhaustive;\n# mod module {#[derive(Default)] pub struct NonExhaustive {pub field: usize, _hack: usize} #[derive(Default)] pub struct PrivateFields { pub pub_field: usize, private_field: usize}} use module::*;\n\nnon_exhaustive!(NonExhaustive { field: 1 });\nnon_exhaustive!(PrivateFields { pub_field: 1 });\n```\n\nUnder the hood, [`non_exhaustive!`] is extremely simple, it expands to:\n\n```rust\n# mod module {#[derive(Default)] pub struct NonExhaustive {pub field: usize, _hack: usize}} use module::*;\n\n{\n  let mut value: NonExhaustive = Default::default();\n  value.field = 1;\n  value\n};\n```\n\n[`non_exhaustive!`]: https://docs.rs/non-exhaustive/latest/non_exhaustive/macro.non_exhaustive.html\n[`Default::default()`]: https://doc.rust-lang.org/std/default/trait.Default.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmodprog%2Fnon-exhaustive","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmodprog%2Fnon-exhaustive","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmodprog%2Fnon-exhaustive/lists"}