{"id":18473903,"url":"https://github.com/ohsayan/derived","last_synced_at":"2025-07-10T00:02:48.656Z","repository":{"id":46700713,"uuid":"410268308","full_name":"ohsayan/derived","owner":"ohsayan","description":"Rust derive macros for automating the boring stuff.","archived":false,"fork":false,"pushed_at":"2021-09-29T16:35:50.000Z","size":127,"stargazers_count":12,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"next","last_synced_at":"2025-07-03T06:39:57.450Z","etag":null,"topics":["crates","proc-macro","rust","rust-lang","rust-library"],"latest_commit_sha":null,"homepage":"https://docs.rs/derived","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/ohsayan.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-09-25T12:35:40.000Z","updated_at":"2025-06-07T17:14:10.000Z","dependencies_parsed_at":"2022-09-13T14:00:39.095Z","dependency_job_id":null,"html_url":"https://github.com/ohsayan/derived","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/ohsayan/derived","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohsayan%2Fderived","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohsayan%2Fderived/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohsayan%2Fderived/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohsayan%2Fderived/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ohsayan","download_url":"https://codeload.github.com/ohsayan/derived/tar.gz/refs/heads/next","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ohsayan%2Fderived/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264505737,"owners_count":23618965,"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":["crates","proc-macro","rust","rust-lang","rust-library"],"created_at":"2024-11-06T10:27:03.518Z","updated_at":"2025-07-10T00:02:48.632Z","avatar_url":"https://github.com/ohsayan.png","language":"Rust","readme":"# `derived`: Macros for automating the boring stuff\n\n![GitHub Workflow Status](https://img.shields.io/github/workflow/status/ohsayan/derived/Test?style=flat-square) [![Crates.io](https://img.shields.io/crates/v/derived?style=flat-square)](https://crates.io/crates/derived) [![docs.rs](https://img.shields.io/docsrs/derived?style=flat-square)](https://docs.rs/derived) [![GitHub](https://img.shields.io/github/license/ohsayan/derived?style=flat-square)](./LICENSE)\n\nThe `derived` crate provides macros that can simplify all the boring stuff, like writing constructors for example. With this crate, you can create **compile-time, constant default implementations**, **constructors**, **getters** and\n**setters** with full generics and lifetime support.\n\n## Features\n\n- **`Ctor`**: To generate **constructors**\n- **`Gtor`**: To generate **getters**\n- **`Stor`**: To generate **setters**\n- **`Constdef`**: To generate **constant, compile-time default implementations**.\n  \u003e 🎉 **Arrays**, **tuples**, **nested tuples in arrays** and **nested arrays in tuples** included!\n- 💯 **Full lifetimes, generics** and **`where` clause support**\n- 🤓 **Advanced features**:\n  - Use the `gtor` attribute to get either immutable or mutable or both references (see example below)\n  - Skip generation of setters or getters with the `#[stor_skip]` or `#[gtor_skip]` attributes for\n    specific fields\n  - Make ctors and gtors `const` with the `#[ctor_const]` and `#[gtor_const]` attributes\n  - Skip ctors, gtors and stors for `PhantomData` fields with the `#[phantom]` attribute\n\n## Example: Constant `default` implementations\n\n```rust\nuse derived::Constdef;\n\n#[derive(Constdef)]\nstruct MyConst {\n    a: u8,\n    b: bool,\n    c: char,\n}\n\nconst MYCONST: MyConst = MyConst::default();\n// use it with other consts\nconst ZERO_U8: u8 = MYCONST.a;\n\nassert_eq!(MYCONST.a, 0);\nassert_eq!(MYCONST.b, false);\nassert_eq!(MYCONST.c, '\\0');\n```\n\n## Example: Generating constructors\n\n```rust\nuse derived::Ctor;\n\n#[derive(Ctor)]\npub struct MyStruct {\n    a: u8,\n    b: i8,\n}\n\nlet mystruct = MyStruct::new(1, -1);\nassert_eq!(mystruct.a, 1);\nassert_eq!(mystruct,b, -1);\n```\n\n## Example: Generating getters\n\n```rust\nuse derived::{Ctor, Gtor};\n\n// we'll derive `Ctor` to avoid having to write ctors\n#[derive(Ctor, Gtor)]\npub struct MyStruct {\n    name: String,\n    userid: u64,\n}\n\nlet ms = MyStruct::new(\"Sayan\".to_owned(), 1);\nassert_eq!(ms.get_name(), \"sayan\");\n// we don't need to deref because u64 is a copy type\nassert_eq!(ms.get_userid(), 1);\n```\n\n## Example: Generating setters\n\n```rust\nuse derived::{Ctor, Stor};\n\n// we'll derive `Ctor` to avoid having to write ctors\n#[derive(Ctor, Stor)]\npub struct MyStruct {\n    name: String,\n    userid: u64,\n}\n\nlet mut ms = MyStruct::new(\"Sayan\".to_owned(), 1);\nassert_eq!(ms.get_name(), \"sayan\");\n// we don't need to deref because u64 is a copy type\nassert_eq!(ms.get_userid(), 1);\nms.set_userid(0);\nassert_eq!(ms.get_userid(), 0);\n```\n\n## Example: Adanced generics and lifetimes in structs\n\n```rust\nuse derived::{Ctor, Gtor};\n\n#[derive(Ctor, Gtor)]\nstruct MyTag\u003c'a, T: ToString\u003e {\n    val: \u0026'a T,\n    tag: u8,\n}\n\nlet mut x = MyTag::new(\u002610i32, 20); // this will have type MyTag\u003ci32\u003e\n// you can now use getters and setters as you please!\nassert_eq!(x.get_val().to_string(), \"10\");\nx.set_val(11);\nassert_eq!(x.get_val().to_string(), \"11\");\n```\n\n## Example: `get_mut` and `get`\n\n```rust\nuse derived::{Ctor, Gtor};\n\n#[derive(Ctor, Gtor)]\n#[gtor(get, get_mut)]\npub struct Mutable {\n    x_axis: u8,\n    y_axis: u8,\n}\n\n#[test]\nfn test_get_and_get_mut() {\n    let mut m = Mutable::new(0, 0);\n    // move x by 1 unit\n    *m.get_x_axis_mut() = 1;\n    // move y by 2 units\n    *m.get_y_axis_mut() = 2;\n    assert_eq!(m.get_x_axis(), 1);\n    assert_eq!(m.get_y_axis(), 2);\n}\n```\n\n## License\n\nThis crate is distributed under the [Apache-2.0 License](./LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fohsayan%2Fderived","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fohsayan%2Fderived","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fohsayan%2Fderived/lists"}