{"id":25092878,"url":"https://github.com/web-coke/super-struct","last_synced_at":"2025-10-22T09:31:55.542Z","repository":{"id":246721652,"uuid":"822038037","full_name":"Web-Coke/super-struct","owner":"Web-Coke","description":"Rust","archived":false,"fork":false,"pushed_at":"2024-07-02T04:12:15.000Z","size":36,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-01-15T11:36:36.165Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Web-Coke.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-30T06:10:14.000Z","updated_at":"2024-07-02T04:12:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"c4254f5d-5af8-4849-8d25-f468354cf704","html_url":"https://github.com/Web-Coke/super-struct","commit_stats":null,"previous_names":["web-coke/super-struct"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Web-Coke%2Fsuper-struct","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Web-Coke%2Fsuper-struct/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Web-Coke%2Fsuper-struct/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Web-Coke%2Fsuper-struct/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Web-Coke","download_url":"https://codeload.github.com/Web-Coke/super-struct/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237663437,"owners_count":19346684,"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":"2025-02-07T14:36:30.776Z","updated_at":"2025-10-22T09:31:50.240Z","avatar_url":"https://github.com/Web-Coke.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e # 💟💟💟小奕💟💟💟\r\n\r\n# Docs\r\n\r\n[![github][github]](https://github.com/Web-Coke/super-struct)\u0026ensp;[![crates-io][crates-io]](https://crates.io/crates/super-struct)\u0026ensp;[![docs-rs][docs-rs]](https://docs.rs/super-struct)\r\n\r\n`super-struct` 旨在帮助开发者像 `Python` 的 `dict` 那样使用 `Rust` 的 `struct`\r\n\r\nThe `super-struct` is designed to help developers use the `struct` of `Rust` in the same way that `dict` of `Python`\r\n\r\n目前这个库的大部分功能已经实现\r\n\r\nMost of the functionality of this library has already been implemented\r\n\r\n还有一部分功能正在积极开发中\r\n\r\nThere are also some features that are under active development\r\n\r\n---\r\n\r\n* [X] 获取 `struct` 中的字段名(keys)\r\n* [X] 获取 `struct` 中的值\r\n* [X] 根据 `struct` 的字段名称(key)获取值\r\n* [X] 根据 `struct` 的字段名称(key)设置值\r\n* [ ] 动态向 `struct` 中添加字段(key)(这个应该很难做到)\r\n\r\n---\r\n\r\n* [X] Get field names (keys) in `struct`\r\n* [X] Get the value in `struct`\r\n* [X] Gets the value based on the field name (key) of `struct`\r\n* [X] Set the value based on the field name (key) of `struct`\r\n* [ ] Dynamically add a field (key) to the `struct` (this should be hard to do)\r\n\r\n---\r\n\r\n如果你有更好的提议或需求欢迎提issue\r\n\r\nIf you have a better proposal or need, please feel free to raise an issue\r\n\r\n# Example\r\n\r\n在Cargo.toml中添加\r\n\r\nAdd in Cargo.toml\r\n\r\n```toml\r\n[dependencies]\r\nsuper-struct = \"*\"\r\n\r\n```\r\n\r\n`struct` 里的类型都一致的情况下\r\n\r\n`struct` is the case where the types are the same\r\n\r\n```rust\r\nuse super_struct::*;\r\n\r\n#[derive(Debug, Rustdict)]\r\nstruct Test {\r\n    name: String,\r\n    country: String,\r\n    language: String,\r\n}\r\n\r\nfn main() {\r\n    let mut test = Test {\r\n        name: \"WebChang\".to_string(),\r\n        country: \"China\".to_string(),\r\n        language: \"Mandarin\".to_string(),\r\n    };\r\n    println!(\"{:?}\", test.keys());\r\n    // [\"name\", \"country\", \"language\"]\r\n\r\n    for i in test.keys() {\r\n        test[i] = \"Hello\".to_string();\r\n        if i == \"language\" {\r\n            test[i] = \"Rust\".to_string()\r\n        }\r\n    }\r\n    println!(\"{:?}\", test);\r\n    // Test { name: \"Hello\", country: \"Hello\", language: \"Rust\" }\r\n\r\n    test.set(\"country\", \"中国\".to_string());\r\n    println!(\"{:?}\", test.values());\r\n    // [\"Hello\", \"中国\", \"Rust\"]\r\n\r\n    test[\"country\"] = test.get(\"language\").clone();\r\n    println!(\"{:?}\", test.values());\r\n    //[\"Hello\", \"Rust\", \"Rust\"]\r\n}\r\n```\r\n\r\n如果 `struct` 里的类型不一致则 `Self[key]` 的语法糖不可用\r\n\r\nIf the types in `struct` are inconsistent, the syntactic sugar for `Self[key]` is not available\r\n\r\n```rust\r\nuse super_struct::*;\r\n\r\n#[derive(Debug, Rustdict)]\r\nstruct Test {\r\n    name: String,\r\n    country: String,\r\n    language: String,\r\n    age: u8,\r\n}\r\n\r\nfn main() {\r\n    let mut test = Test {\r\n        name: \"WebChang\".to_string(),\r\n        country: \"China\".to_string(),\r\n        language: \"Mandarin\".to_string(),\r\n        age: 24u8,\r\n    };\r\n    println!(\"{:?}\", test.keys());\r\n    // [\"name\", \"country\", \"language\", \"age\"]\r\n    println!(\"{:?}\", test.values());\r\n    // [Any { .. }, Any { .. }, Any { .. }, Any { .. }]\r\n\r\n    for i in test.keys() {\r\n        test.set(i, \u0026\"Hello\".to_string());\r\n        // 如果类型不一致则什么都不会发生\r\n        // If the types are inconsistent, nothing happens\r\n        // if i == \u0026\"age\" {\r\n        //     test.set(i, \u002625u8)\r\n        // }\r\n    }\r\n    println!(\"{:?}\", test);\r\n    // Test { name: \"Hello\", country: \"Hello\", language: \"Hello\", age: 24 }\r\n\r\n    test.set(\"age\", \u002625u8);\r\n    println!(\"{:?}\", test);\r\n    // Test { name: \"Hello\", country: \"Hello\", language: \"Hello\", age: 25 }\r\n\r\n    println!(\r\n        \"{:?}\",\r\n        test.get(\"language\").downcast_ref::\u003cString\u003e().unwrap()\r\n    );\r\n    // \"Hello\"\r\n}\r\n```\r\n\r\n# Changelog\r\n\r\n## 0.1.0\r\n\r\n* 初始版本\r\n* Initial release\r\n\r\n## 1.0.0 \u0026 1.0.1\r\n\r\n* 更正文档错误\r\n* Correct document errors\r\n\r\n## 1.0.2\r\n\r\n* 添加对 `where` 子句的支持\r\n* Adds support for the `where` clause\r\n* 修改 `Self.keys(\u0026self) -\u003e \u0026'static[\u0026'static str]` 为 `Self::keys() -\u003e Vec\u003c\u0026'static str\u003e`\r\n* Changed `Self.keys(\u0026self) -\u003e \u0026'static[\u0026'static str]` to `Self::keys() -\u003e Vec\u003c\u0026'static str\u003e`\r\n* 详细请移步到 [Github](https://github.com/Web-Coke/super-struct)\r\n* For more details, please move to [Github](https://github.com/Web-Coke/super-struct)\r\n\r\n[github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge\u0026labelColor=555555\u0026logo=github\r\n[crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge\u0026labelColor=555555\u0026logo=rust\r\n[docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge\u0026labelColor=555555\u0026logo=docs.rs\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweb-coke%2Fsuper-struct","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweb-coke%2Fsuper-struct","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweb-coke%2Fsuper-struct/lists"}