{"id":33939210,"url":"https://github.com/bytedream/serde-inline-default","last_synced_at":"2026-01-24T17:03:54.895Z","repository":{"id":65811973,"uuid":"600448294","full_name":"bytedream/serde-inline-default","owner":"bytedream","description":"Serde default values via inline attribute declaration","archived":false,"fork":false,"pushed_at":"2025-09-02T12:14:37.000Z","size":29,"stargazers_count":36,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-02T09:09:27.701Z","etag":null,"topics":["rust","rust-serde","serde","serde-json","serde-serialization"],"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/bytedream.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,"zenodo":null}},"created_at":"2023-02-11T14:28:45.000Z","updated_at":"2025-12-24T15:59:22.000Z","dependencies_parsed_at":"2025-04-11T19:37:58.715Z","dependency_job_id":"9f7490eb-2706-428c-93a9-a1cd57f16872","html_url":"https://github.com/bytedream/serde-inline-default","commit_stats":{"total_commits":10,"total_committers":2,"mean_commits":5.0,"dds":0.09999999999999998,"last_synced_commit":"85b1fbdfcd35cbbc8893019f45d075c7712f0ed5"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/bytedream/serde-inline-default","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytedream%2Fserde-inline-default","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytedream%2Fserde-inline-default/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytedream%2Fserde-inline-default/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytedream%2Fserde-inline-default/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bytedream","download_url":"https://codeload.github.com/bytedream/serde-inline-default/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytedream%2Fserde-inline-default/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28732218,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-24T10:24:43.181Z","status":"ssl_error","status_checked_at":"2026-01-24T10:24:36.112Z","response_time":89,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["rust","rust-serde","serde","serde-json","serde-serialization"],"created_at":"2025-12-12T15:16:35.456Z","updated_at":"2026-01-24T17:03:54.871Z","avatar_url":"https://github.com/bytedream.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# serde-inline-default [![ci](https://github.com/ByteDream/serde-inline-default/actions/workflows/ci.yml/badge.svg)](https://github.com/ByteDream/serde-inline-default/actions/workflows/ci.yml) [![crates.io](https://img.shields.io/crates/v/serde-inline-default)](https://crates.io/crates/serde-inline-default) [![crates.io downloads](https://img.shields.io/crates/d/serde-inline-default)](https://crates.io/crates/serde-inline-default) [![docs](https://img.shields.io/docsrs/serde-inline-default)](https://docs.rs/serde-inline-default/latest/serde_inline_default/)\n\nA tiny crate to set default values for serde struct fields via inline attribute declaration.\n\n## Overview\n\nThis crate is an approach to do what [serde-rs/serde#368](https://github.com/serde-rs/serde/issues/368) purposes: Defining default values for struct fields via inline declaration instead of creating a separate function for it.\n\nSo instead of writing something like this, which can get very verbose quickly with many fields:\n```rust\n#[derive(Deserialize)]\nstruct Test {\n    #[serde(default = \"value_default\")]\n    value: u32\n}\n\nfn value_default() -\u003e u32 { 42 }\n```\nyou can just do this:\n```rust\n#[serde_inline_default]\n#[derive(Deserialize)]\nstruct Test {\n    #[serde_inline_default(42)]\n    value: u32\n}\n```\n\n\u003e [!IMPORTANT]\n\u003e **`#[serde_inline_default]` must be set before `#[derive(Deserialize)]`/`#[derive(Serialize)]`!**\n\nInternally, `#[serde_inline_default(...)]` gets expanded to a function which returns the set value and the attribute is replaced with `#[serde(default = \"\u003cfunction name\u003e\")]`.\nSo this macro is just some syntax sugar for you, but can get quite handy if you want to keep your code clean or write declarative macros / `macro_rules!`.\n\n## Alternatives\n\nThis crate isn't perfect. Thus, you might be more satisfied with alternatives `serde` provides.\n\nWith `#[serde(default)]` + `impl Default` on a struct, `serde` uses the default implementation of the struct to get default values for each field ([docs](https://serde.rs/container-attrs.html#default)):\n```rust\n#[derive(Deserialize)]\n#[serde(default)]\nstruct Test {\n    value: u32\n}\n\nimpl Default for Test {\n    fn default() -\u003e Self {\n        Self {\n            value: 42\n        }\n    }\n}\n```\n\nIf you still need/want `serde-inline-default` features, you also can combine them with `#[serde(default))` and `impl Default`:\n```rust\n#[serde_inline_default]\n#[derive(Deserialize)]\n#[serde(default)]\nstruct Test {\n    value: u32,\n    #[serde_inline_default(0)]\n    other_value: u32,\n}\n\nimpl Default for Test {\n    fn default() -\u003e Self {\n        Self {\n            value: 42,\n            other_value: 42\n        }\n    }\n}\n```\n\n## License\n\nThis project is licensed under either of the following licenses, at your option:\n\n- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or \u003chttp://www.apache.org/licenses/LICENSE-2.0\u003e)\n- MIT License ([LICENSE-MIT](LICENSE-MIT) or \u003chttp://opensource.org/licenses/MIT\u003e)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytedream%2Fserde-inline-default","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbytedream%2Fserde-inline-default","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytedream%2Fserde-inline-default/lists"}