{"id":22426612,"url":"https://github.com/theypsilon/getters-by-type-rs","last_synced_at":"2025-06-23T17:09:23.322Z","repository":{"id":62439414,"uuid":"176025092","full_name":"theypsilon/getters-by-type-rs","owner":"theypsilon","description":"Derive macro for adding a getter method for each type in the struct.","archived":false,"fork":false,"pushed_at":"2019-03-20T23:19:47.000Z","size":49,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-01T08:43:51.929Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/theypsilon.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2019-03-16T21:10:01.000Z","updated_at":"2021-05-20T08:34:40.000Z","dependencies_parsed_at":"2022-11-01T22:00:43.161Z","dependency_job_id":null,"html_url":"https://github.com/theypsilon/getters-by-type-rs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/theypsilon/getters-by-type-rs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theypsilon%2Fgetters-by-type-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theypsilon%2Fgetters-by-type-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theypsilon%2Fgetters-by-type-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theypsilon%2Fgetters-by-type-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theypsilon","download_url":"https://codeload.github.com/theypsilon/getters-by-type-rs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theypsilon%2Fgetters-by-type-rs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261519031,"owners_count":23171227,"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-12-05T19:22:46.026Z","updated_at":"2025-06-23T17:09:23.294Z","avatar_url":"https://github.com/theypsilon.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Getters By Type\n\n[![Crates.io](https://img.shields.io/crates/v/getters-by-type.svg)](https://crates.io/crates/getters-by-type)\n[![Docs](https://docs.rs/getters-by-type/badge.svg)](https://docs.rs/getters-by-type)\n\nThis crate provides `GettersByType` derive macro for structs, which implements a getter method for each type they contain.\n\nThe generated methods start with the prefix `get_fields_` and end with a transcription of the type they refer.\n\nExample using `GettersByType` :\n\n```rust\n#[derive(GettersByType)]\nstruct Foo {\n    first: i32,\n    second: i32,\n    third: i32,\n}\n\nlet object = Foo { first: 6, second: 12, third: 24 };\n\n// Let's sum all the i32 fields with a fold expression:\nassert_eq!(object.get_fields_i32().iter().fold(0, |acc, x| **x + acc), 42);\n```\n\nAs you notice, the getter methods return an array containing references to all the fields of the same type.\nIn that example, the return type of the method `get_fields_i32` would be `[\u0026i32; 3]`.\n\nThis crate also provides a `mut` version `GettersMutByType` which also adds a mut version for those methods.\n\nIn this case, the generated methods start with the prefix `get_mut_fields_` instead.\n\nExample using `GettersMutByType` :\n\n\n```rust\n#[derive(GettersMutByType)]\nstruct Foo {\n    first: Updater,\n    second: Updater,\n    ...\n    onehundredth: Updater,\n}\n\nimpl Updater {\n    fn update(\u0026mut self) {...}\n}\n\nlet mut object = Foo::new();\n\n// Let's update all the Updater fields\nfor updater in object.get_mut_fields_updater().iter_mut() {\n    updater.update();\n}\n```\n\nIn this example, the return type of the method `get_mut_fields_updater` would be `[\u0026mut Updater; 3]`.\nThere is no dynamic memory allocation happening within the getter methods, as they just return a fixed array with references.\nThere isn't also unsafe code being generated.\n\nFor more information, check the [documentation page](https://docs.rs/getters-by-type).\n\n## Usage\n\nWith Cargo, you can add this line to your Cargo.toml:\n\n```toml\n[dependencies]\ngetters-by-type = \"*\"\n```\n\n## Development\n\nThis currently works with primitive types, and many other referencial and genecic types, such as `\u0026str` or `Vec`, but there are cases that are not completely covered, like the trait objects. Want to contribute? Pull requests are always welcome. Because this is my first work with procedural macros, I guess things can improve a fair lot under the hood, so there should be a few low hanging fruits already. Let's go for them!\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheypsilon%2Fgetters-by-type-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftheypsilon%2Fgetters-by-type-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheypsilon%2Fgetters-by-type-rs/lists"}