{"id":15049515,"url":"https://github.com/editso/c2rs","last_synced_at":"2026-01-02T00:14:47.287Z","repository":{"id":45301716,"uuid":"441071932","full_name":"editso/c2rs","owner":"editso","description":"将C结构体转换为Rust结构体","archived":false,"fork":false,"pushed_at":"2021-12-28T07:01:41.000Z","size":10,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-24T08:29:24.880Z","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/editso.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":"2021-12-23T05:26:45.000Z","updated_at":"2021-12-28T07:01:44.000Z","dependencies_parsed_at":"2022-09-07T13:51:20.943Z","dependency_job_id":null,"html_url":"https://github.com/editso/c2rs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/editso%2Fc2rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/editso%2Fc2rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/editso%2Fc2rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/editso%2Fc2rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/editso","download_url":"https://codeload.github.com/editso/c2rs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243510126,"owners_count":20302294,"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-09-24T21:21:05.292Z","updated_at":"2026-01-02T00:14:47.250Z","avatar_url":"https://github.com/editso.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# c2rs \nThis is a macro that converts the `struct` of the `c` language into a `rust struct`\n\n[![Crates.io][crates-badge]][crates-url]\n[![MIT licensed][mit-badge]][mit-url]\n\n[crates-badge]: https://img.shields.io/crates/v/c2rs.svg\n[crates-url]: https://crates.io/crates/c2rs\n[mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg\n[mit-url]: https://github.com/editso/c2rs/blob/master/LICENSE\n\n# use\n```\n// Cargo.toml\n\n[dependencies]\nc2rs = \"0.1.2\"\n\n```\n\n# Example\n```\nfn test(){\n    use c2rs::c2rs_def;\n\n    type DWORD = u32;\n    const SIZE: usize = 10;\n\n    c2rs_def!(\n        struct A{\n            DWORD var1;\n            DWORD var2;\n            union {\n                DWORD var4;\n                DWORD var5;   \n            }var3;\n            \n            struct {\n                u8 var7;\n            }var6;\n\n            DWORD array[SIZE];\n        };\n        \n        struct B{\n            u8 var1;\n        };\n        \n        // ....\n    );\n    \n    let mut buffer = [1u8; 1024];\n    \n    unsafe{\n        let mut buf = A::from_mut_bytes(buffer.as_mut_ptr());\n        let buf = buf.as_mut().unwrap();\n        buf.var1 = 10;\n        \n        assert_eq!(10, buf.var1);\n        assert_eq!(10, buffer[0]);\n        \n        let mut b = B::from_mut_bytes(buffer.as_mut_ptr()).as_mut().unwrap();\n        \n        assert_eq!(10, b.var1);\n    \n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feditso%2Fc2rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feditso%2Fc2rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feditso%2Fc2rs/lists"}