{"id":16714180,"url":"https://github.com/flier/named-tuple.rs","last_synced_at":"2026-03-27T04:24:54.864Z","repository":{"id":57643221,"uuid":"166002501","full_name":"flier/named-tuple.rs","owner":"flier","description":"A macro for declaring a struct that manages a set of fields in a tuple.","archived":false,"fork":false,"pushed_at":"2019-04-21T11:22:59.000Z","size":28,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T07:14:21.344Z","etag":null,"topics":[],"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/flier.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}},"created_at":"2019-01-16T08:23:52.000Z","updated_at":"2023-10-08T20:04:40.000Z","dependencies_parsed_at":"2022-08-30T04:53:09.144Z","dependency_job_id":null,"html_url":"https://github.com/flier/named-tuple.rs","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flier%2Fnamed-tuple.rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flier%2Fnamed-tuple.rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flier%2Fnamed-tuple.rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flier%2Fnamed-tuple.rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flier","download_url":"https://codeload.github.com/flier/named-tuple.rs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248130224,"owners_count":21052721,"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-12T20:49:47.197Z","updated_at":"2026-03-27T04:24:49.821Z","avatar_url":"https://github.com/flier.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"named-tuple.rs\n==============\n\nA macro for declaring a `struct` that manages a set of fields in a `tuple`.\n\n[![Travis-CI Status](https://travis-ci.org/flier/named-tuple.rs.svg?branch=master)](https://travis-ci.org/flier/named-tuple.rs)\n[![Latest version](https://img.shields.io/crates/v/named_tuple.svg)](https://crates.io/crates/named_tuple)\n[![Documentation](https://docs.rs/named_tuple/badge.svg)](https://docs.rs/named_tuple)\n[![License](https://img.shields.io/crates/l/named_tuple.svg)](https://github.com/flier/named-tuple.rs#license)\n\n# Getting Started\n\n[named-tuple.rs is available on crates.io](https://crates.io/crates/named_tuple).\nIt is recommended to look there for the newest released version, as well as links to the newest builds of the docs.\n\nAt the point of the last update of this README, the latest published version could be used like this:\n\nAdd the following dependency to your Cargo manifest...\n\n```toml\n[dependencies]\nnamed_tuple = \"0.1\"\n```\n\n...and see the [docs](https://docs.rs/named_tuple) for how to use it.\n\n# Example\n\n```rust\n#[macro_use]\nextern crate named_tuple;\n\nnamed_tuple!(\n    #[derive(Clone, Copy, Debug, Default, Hash, PartialEq)]\n    struct Human\u003c'a\u003e {\n        name: \u0026'a str,\n        age: usize,\n    }\n);\n\nnamed_tuple!(\n    #[derive(Copy, Debug)]\n    struct Endpoint(host, port);\n);\n\nfn main() {\n    /// structs with named fields\n    let mut human = Human::new(\"alice\", 18);\n\n    assert_eq!(Human::field_names(), \u0026[\"name\", \"age\"]);\n    assert_eq!(human.fields(), ((\"name\", \"alice\"), (\"age\", 18)));\n    assert_eq!(human.field_values(), (\"alice\", 18));\n\n    assert_eq!(human.name(), \"alice\");\n    assert_eq!(human.age(), 18);\n\n    assert_eq!((human.0).0, \"alice\");\n    assert_eq!((human.0).1, 18);\n\n    assert_eq!(format!(\"{:?}\", human), \"Human { name: \\\"alice\\\", age: 18 }\");\n\n    human.set_name(\"bob\");\n    assert_eq!(human, (\"bob\", 18));\n\n    human.set_age(20);\n    assert_eq!(human, Human::from((\"bob\", 20)));\n\n    let t: (\u0026str, usize) = human.into();\n\n    assert_eq!(t, (\"bob\", 20));\n\n    // tuple structs\n    let mut endpoint = Endpoint::new(\"localhost\", 80);\n\n    assert_eq!(endpoint.field_names(), \u0026[\"host\", \"port\"]);\n    assert_eq!(endpoint.fields(), ((\"host\", \"localhost\"), (\"port\", 80)));\n    assert_eq!(endpoint.field_values(), (\"localhost\", 80));\n\n    assert_eq!(endpoint.host(), \"localhost\");\n    assert_eq!(endpoint.port(), 80);\n\n    assert_eq!(\n        format!(\"{:?}\", endpoint),\n        \"Endpoint { host: \\\"localhost\\\", port: 80 }\"\n    );\n\n    endpoint.set_host(\"google.com\");\n    endpoint.set_port(443);\n\n    assert_eq!((\"google.com\", 443), endpoint.into());\n}\n```\n\n## License\n\nLicensed under either of\n\n * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n### Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflier%2Fnamed-tuple.rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflier%2Fnamed-tuple.rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflier%2Fnamed-tuple.rs/lists"}