{"id":33936450,"url":"https://github.com/andrewsonin/gset","last_synced_at":"2026-04-04T12:58:19.568Z","repository":{"id":65166205,"uuid":"585111438","full_name":"andrewsonin/gset","owner":"andrewsonin","description":"Getters and Setters for Rust.","archived":false,"fork":false,"pushed_at":"2024-07-23T15:49:27.000Z","size":26,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-14T02:00:13.358Z","etag":null,"topics":["getter","getters","getters-and-setters","proc-macro","rust","rust-macro","rust-proc-macro","setter","setters"],"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/andrewsonin.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-04T10:50:47.000Z","updated_at":"2025-09-02T03:49:54.000Z","dependencies_parsed_at":"2024-07-23T18:25:10.517Z","dependency_job_id":null,"html_url":"https://github.com/andrewsonin/gset","commit_stats":{"total_commits":2,"total_committers":1,"mean_commits":2.0,"dds":0.0,"last_synced_commit":"1dc857e31f8687cac52bea03d8d00e71510b99a2"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/andrewsonin/gset","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewsonin%2Fgset","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewsonin%2Fgset/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewsonin%2Fgset/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewsonin%2Fgset/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrewsonin","download_url":"https://codeload.github.com/andrewsonin/gset/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrewsonin%2Fgset/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31400460,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-04T10:20:44.708Z","status":"ssl_error","status_checked_at":"2026-04-04T10:20:06.846Z","response_time":60,"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":["getter","getters","getters-and-setters","proc-macro","rust","rust-macro","rust-proc-macro","setter","setters"],"created_at":"2025-12-12T14:16:16.002Z","updated_at":"2026-04-04T12:58:19.555Z","avatar_url":"https://github.com/andrewsonin.png","language":"Rust","readme":"# gset\n\n_Getters and Setters for Rust._\n\n[![Crates.io][crates-badge]][crates-url]\n[![Documentation][docs-badge]][docs-url]\n[![MIT licensed][mit-badge]][mit-url]\n[![Build Status][actions-badge]][actions-url]\n\n[crates-badge]: https://img.shields.io/crates/v/gset.svg\n[crates-url]: https://crates.io/crates/gset\n[docs-badge]: https://img.shields.io/docsrs/gset\n[docs-url]: https://docs.rs/gset\n[mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg\n[mit-url]: https://github.com/andrewsonin/gset/blob/main/LICENSE\n[actions-badge]: https://github.com/andrewsonin/gset/actions/workflows/ci.yml/badge.svg\n[actions-url]: https://github.com/andrewsonin/gset/actions/workflows/ci.yml\n\nProvides a procedural macro capable of deriving  basic getters and setters for structs.\n\n## Usage example\n\nAn example of using this library is provided below.\n\n```rust\nuse gset::Getset;\n\n#[derive(Getset)]\nstruct Struct\u003cT\u003e\n{\n    /// Field 1.\n    #[getset(get_copy, name = \"get_field_1\", vis = \"pub\")]\n    #[getset(set)]\n    field_1: f64,\n\n    /// Field 2.\n    #[getset(get_deref, vis = \"pub\")]\n    #[getset(get_deref_mut, vis = \"pub\")]\n    #[getset(set, vis = \"pub\")]\n    field_2: Vec\u003cT\u003e,\n}\n```\n\nThis also works well for tuple structures,\nbut the `name` parameter becomes mandatory.\n\n```rust\nuse gset::Getset;\n\n#[derive(Getset)]\nstruct Struct\u003cT\u003e(\n\n    /// Field 1.\n    #[getset(get_copy, name = \"get_field_1\", vis = \"pub\")]\n    #[getset(set, name = \"set_field_1\")]\n    f64,\n\n    /// Field 2.\n    #[getset(get_deref, name = \"get_field_2\", vis = \"pub\")]\n    #[getset(get_deref_mut, name = \"get_field_2_mut\", vis = \"pub\")]\n    #[getset(set, name = \"set_field_2\", vis = \"pub\")]\n    Vec\u003cT\u003e,\n);\n```\n\n## Field attributes\n\nAll field attributes have the following named parameters:\n- `name` — name of the method being inferred.\n  Must be a valid Rust [identifier](https://docs.rs/syn/1.0.109/syn/struct.Ident.html).\n  This is a required parameter for tuple structs.\n- `vis` — visibility of the method being inferred.\n  Must be a valid Rust [visibility modifier](https://docs.rs/syn/1.0.109/syn/enum.Visibility.html).\n  Visibility is `private` by default.\n\nAnd some of them have the following named parameter:\n- `ty` — return type of the method being inferred. Must be a valid Rust [type](https://docs.rs/syn/1.0.109/syn/enum.Type.html).\n\n#### Legend\nHere and further we will adhere to the following notation.\n- `field` — field name.\n- `T` — field type.\n\nThe field attributes currently supported are listed below.\n\n### 1. `get`\n\nDerives a reference getter for a field.\n\n#### Parameters\n- `name` — name of the resulting method. If not set, it will be named as `field`.\n- `vis` — visibility of the resulting method. If not set, it will be private.\n- `ty` — return type of the resulting method. If not set, it will have the `\u0026T` return type.\n\n#### Example\n\n```rust\nuse gset::Getset;\n\n#[derive(Getset)]\nstruct Struct {\n    /// Doc comment.\n    #[getset(get, vis = \"pub\")]\n    a: f64,\n}\n```\nwill expand into\n```rust\nstruct Struct {\n    /// Doc comment.\n    a: f64,\n}\n\nimpl Struct {\n    /// Doc comment.\n    #[inline]\n    pub fn a(\u0026self) -\u003e \u0026f64 {\n        \u0026self.a\n    }\n}\n```\n\n### 2. `get_mut`\n\nDerives a mutable getter for a field.\n\n#### Parameters\n- `name` — name of the resulting method. If not set, it will be named as `field_mut`.\n- `vis` — visibility of the resulting method. If not set, it will be private.\n- `ty` — return type of the resulting method. If not set, it will have the `\u0026mut T` return type.\n\n#### Example\n\n```rust\nuse gset::Getset;\n\n#[derive(Getset)]\nstruct Struct {\n    /// Doc comment.\n    #[getset(get_mut, vis = \"pub\")]\n    a: f64,\n}\n```\nwill expand into\n```rust\nstruct Struct {\n    /// Doc comment.\n    a: f64,\n}\n\nimpl Struct {\n    /// Doc comment.\n    #[inline]\n    pub fn a_mut(\u0026mut self) -\u003e \u0026mut f64 {\n        \u0026mut self.a\n    }\n}\n```\n\n### 3. `get_copy`\n\nDerives a copy getter for a field.\n\n#### Parameters\n- `name` — name of the resulting method. If not set, it will be named as `field`.\n- `vis` — visibility of the resulting method. If not set, it will be private.\n- `ty` — return type of the resulting method. If not set, it will have the `T` return type.\n\n#### Example\n\n```rust\nuse gset::Getset;\n\n#[derive(Getset)]\nstruct Struct {\n    /// Doc comment.\n    #[getset(get_copy, vis = \"pub\")]\n    a: f64,\n}\n```\nwill expand into\n```rust\nstruct Struct {\n    /// Doc comment.\n    a: f64,\n}\n\nimpl Struct {\n    /// Doc comment.\n    #[inline]\n    pub fn a(\u0026self) -\u003e f64 {\n        self.a\n    }\n}\n```\n\n### 4. `get_deref`\n\nDerives a reference getter for a field, which applies the `deref` operation to the resulting reference.\n\n#### Parameters\n- `name` — name of the resulting method. If not set, it will be named as `field`.\n- `vis` — visibility of the resulting method. If not set, it will be private.\n- `ty` — return type of the resulting method. If not set, it will have the `\u0026\u003cT as ::std::ops:Deref\u003e::Target` return type.\n\n#### Example\n\n```rust\nuse gset::Getset;\n\n#[derive(Getset)]\nstruct Struct {\n    /// Doc comment.\n    #[getset(get_deref, vis = \"pub\")]\n    a: Vec\u003cf64\u003e,\n}\n```\nwill expand into\n```rust\nstruct Struct {\n    /// Doc comment.\n    a: Vec\u003cf64\u003e,\n}\n\nimpl Struct {\n    /// Doc comment.\n    #[inline]\n    pub fn a(\u0026self) -\u003e \u0026[f64] {\n        \u0026self.a\n    }\n}\n```\n\n### 5. `get_deref_mut`\n\nDerives a mutable getter for a field, which applies the `deref_mut` operation to the resulting reference.\n\n#### Parameters\n- `name` — name of the resulting method. If not set, it will be named as `field_mut`.\n- `vis` — visibility of the resulting method. If not set, it will be private.\n- `ty` — return type of the resulting method. If not set, it will have the `\u0026mut \u003cT as ::std::ops:Deref\u003e::Target` return type.\n\n#### Example\n\n```rust\nuse gset::Getset;\n\n#[derive(Getset)]\nstruct Struct {\n    /// Doc comment.\n    #[getset(get_deref_mut, vis = \"pub\")]\n    a: Vec\u003cf64\u003e,\n}\n```\nwill expand into\n```rust\nstruct Struct {\n    /// Doc comment.\n    a: Vec\u003cf64\u003e,\n}\n\nimpl Struct {\n    /// Doc comment.\n    #[inline]\n    pub fn a_mut(\u0026mut self) -\u003e \u0026mut [f64] {\n        \u0026mut self.a\n    }\n}\n```\n\n### 6. `get_deref_copy`\n\nDerives a copy getter for a field, which applies dereferencing to the field value.\n\n#### Parameters\n- `name` — name of the resulting method. If not set, it will be named as `field`.\n- `vis` — visibility of the resulting method. If not set, it will be private.\n- `ty` — return type of the resulting method. If not set, it will have the `\u003cT as ::std::ops:Deref\u003e::Target` return type.\n\n#### Example\n\n```rust\nuse derive_more::Deref;\nuse gset::Getset;\n\n#[derive(Getset)]\nstruct Struct {\n    /// Doc comment.\n    #[getset(get_deref_copy, vis = \"pub\")]\n    a: F64,\n}\n\n#[derive(Deref)]\nstruct F64(f64);\n```\nwill expand into\n```rust\nuse derive_more::Deref;\n\nstruct Struct {\n    /// Doc comment.\n    a: F64,\n}\n\n#[derive(Deref)]\nstruct F64(f64);\n\nimpl Struct {\n    /// Doc comment.\n    #[inline]\n    pub fn a(\u0026self) -\u003e f64 {\n        *self.a\n    }\n}\n```\n\n### 7. `get_as_ref`\n\nDerives a reference getter for a field, which applies the `as_ref` operation to the resulting reference.\n\n#### Parameters\n- `name` — name of the resulting method. If not set, it will be named as `field`.\n- `vis` — visibility of the resulting method. If not set, it will be private.\n- `ty` — return type of the resulting method. Required parameter.\n\n#### Example\n\n```rust\nuse gset::Getset;\n\n#[derive(Getset)]\nstruct Struct {\n    /// Doc comment.\n    #[getset(get_as_ref, vis = \"pub\", ty = \"Option\u003c\u0026f64\u003e\")]\n    a: Option\u003cf64\u003e,\n}\n```\nwill expand into\n```rust\nstruct Struct {\n    /// Doc comment.\n    a: Option\u003cf64\u003e,\n}\n\nimpl Struct {\n    /// Doc comment.\n    #[inline]\n    pub fn a(\u0026self) -\u003e Option\u003c\u0026f64\u003e {\n        self.a.as_ref()\n    }\n}\n```\n\n### 8. `get_as_deref`\n\nDerives a reference getter for a field, which applies the `as_deref` operation to the resulting reference.\n\n#### Parameters\n- `name` — name of the resulting method. If not set, it will be named as `field`.\n- `vis` — visibility of the resulting method. If not set, it will be private.\n- `ty` — return type of the resulting method. Required parameter.\n\n#### Example\n\n```rust\nuse derive_more::Deref;\nuse gset::Getset;\n\n#[derive(Getset)]\nstruct Struct {\n    /// Doc comment.\n    #[getset(get_as_deref, vis = \"pub\", ty = \"Option\u003c\u0026f64\u003e\")]\n    a: Option\u003cF64\u003e,\n}\n\n#[derive(Deref)]\nstruct F64(f64);\n```\nwill expand into\n```rust\nuse derive_more::Deref;\n\nstruct Struct {\n    /// Doc comment.\n    a: Option\u003cF64\u003e,\n}\n\n#[derive(Deref)]\nstruct F64(f64);\n\nimpl Struct {\n    /// Doc comment.\n    #[inline]\n    pub fn a(\u0026self) -\u003e Option\u003c\u0026f64\u003e {\n        self.a.as_deref()\n    }\n}\n```\n\n### 9. `get_as_deref_mut`\n\nDerives a mutable getter for a field, which applies the `as_deref_mut` operation to the resulting reference.\n\n#### Parameters\n- `name` — name of the resulting method. If not set, it will be named as `field_mut`.\n- `vis` — visibility of the resulting method. If not set, it will be private.\n- `ty` — return type of the resulting method. Required parameter.\n\n#### Example\n\n```rust\nuse derive_more::{Deref, DerefMut};\nuse gset::Getset;\n\n#[derive(Getset)]\nstruct Struct {\n    /// Doc comment.\n    #[getset(get_as_deref_mut, vis = \"pub\", ty = \"Option\u003c\u0026mut f64\u003e\")]\n    a: Option\u003cF64\u003e,\n}\n\n#[derive(Deref, DerefMut)]\nstruct F64(f64);\n```\nwill expand into\n```rust\nuse derive_more::{Deref, DerefMut};\n\nstruct Struct {\n    /// Doc comment.\n    a: Option\u003cF64\u003e,\n}\n\n#[derive(Deref, DerefMut)]\nstruct F64(f64);\n\nimpl Struct {\n    /// Doc comment.\n    #[inline]\n    pub fn a_mut(\u0026mut self) -\u003e Option\u003c\u0026mut f64\u003e {\n        self.a.as_deref_mut()\n    }\n}\n```\n\n### 10. `set`\n\nDerives a setter for a field.\n\n#### Parameters\n- `name` — name of the resulting method. If not set, it will be named as `set_field`.\n- `vis` — visibility of the resulting method. If not set, it will be private.\n\n#### Example\n\n```rust\nuse gset::Getset;\n\n#[derive(Getset)]\nstruct Struct {\n    /// Doc comment.\n    #[getset(set, vis = \"pub\")]\n    a: f64,\n}\n```\nwill expand into\n```rust\nstruct Struct {\n    /// Doc comment.\n    a: f64,\n}\n\nimpl Struct {\n    /// Doc comment.\n    #[inline]\n    pub fn set_a(\u0026mut self, value: f64) {\n        self.a = value\n    }\n}\n```\n\n### 11. `set_borrow`\n\nDerives a borrowing setter for a field.\n\n#### Parameters\n- `name` — name of the resulting method. If not set, it will be named as `set_field`.\n- `vis` — visibility of the resulting method. If not set, it will be private.\n\n#### Example\n\n```rust\nuse gset::Getset;\n\n#[derive(Getset)]\nstruct Struct {\n    /// Doc comment.\n    #[getset(set_borrow, vis = \"pub\")]\n    a: f64,\n}\n```\nwill expand into\n```rust\nstruct Struct {\n    /// Doc comment.\n    a: f64,\n}\n\nimpl Struct {\n    /// Doc comment.\n    #[inline]\n    pub fn set_a(\u0026mut self, value: f64) -\u003e \u0026mut Self {\n        self.a = value;\n        self\n    }\n}\n```\n\n### 12. `set_own`\n\nDerives an owning setter for a field.\n\n#### Parameters\n- `name` — name of the resulting method. If not set, it will be named as `set_field`.\n- `vis` — visibility of the resulting method. If not set, it will be private.\n\n#### Example\n\n```rust\nuse gset::Getset;\n\n#[derive(Getset)]\nstruct Struct {\n    /// Doc comment.\n    #[getset(set_own, vis = \"pub\")]\n    a: f64,\n}\n```\nwill expand into\n```rust\nstruct Struct {\n    /// Doc comment.\n    a: f64,\n}\n\nimpl Struct {\n    /// Doc comment.\n    #[inline]\n    pub fn set_a(mut self, value: f64) -\u003e Self {\n        self.a = value;\n        self\n    }\n}\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewsonin%2Fgset","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrewsonin%2Fgset","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrewsonin%2Fgset/lists"}