{"id":13439119,"url":"https://github.com/fizyk20/generic-array","last_synced_at":"2025-10-18T16:06:06.461Z","repository":{"id":45161948,"uuid":"43086384","full_name":"fizyk20/generic-array","owner":"fizyk20","description":"Generic array types in Rust","archived":false,"fork":false,"pushed_at":"2025-03-06T17:31:19.000Z","size":23103,"stargazers_count":408,"open_issues_count":9,"forks_count":78,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-05-07T00:04:59.166Z","etag":null,"topics":["rust"],"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/fizyk20.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":"2015-09-24T18:52:33.000Z","updated_at":"2025-05-05T06:36:03.000Z","dependencies_parsed_at":"2023-02-01T04:01:03.721Z","dependency_job_id":"3349176b-9543-4ab4-869d-f3cecb050af7","html_url":"https://github.com/fizyk20/generic-array","commit_stats":{"total_commits":300,"total_committers":38,"mean_commits":7.894736842105263,"dds":0.4633333333333334,"last_synced_commit":"5fd47c916fe334d89e3bb84d04ade2f788750d31"},"previous_names":[],"tags_count":48,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fizyk20%2Fgeneric-array","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fizyk20%2Fgeneric-array/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fizyk20%2Fgeneric-array/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fizyk20%2Fgeneric-array/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fizyk20","download_url":"https://codeload.github.com/fizyk20/generic-array/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252973690,"owners_count":21834108,"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":["rust"],"created_at":"2024-07-31T03:01:11.301Z","updated_at":"2025-10-18T16:06:01.420Z","avatar_url":"https://github.com/fizyk20.png","language":"Rust","readme":"[![Crates.io](https://img.shields.io/crates/v/generic-array.svg)](https://crates.io/crates/generic-array)\n[![Build Status](https://github.com/fizyk20/generic-array/actions/workflows/CI.yml/badge.svg)](https://github.com/fizyk20/generic-array/actions/workflows/CI.yml)\n# generic-array\n\nThis crate implements a structure that can be used as a generic array type.\n\n**Requires minimum Rust version of 1.83.0\n\n[Documentation on GH Pages](https://fizyk20.github.io/generic-array/generic_array/) may be required to view certain types on foreign crates.\n\n## Usage\n\nBefore Rust 1.51, arrays `[T; N]` were problematic in that they couldn't be generic with respect to the length `N`, so this wouldn't work:\n\n```rust\nstruct Foo\u003cN\u003e {\n    data: [i32; N],\n}\n```\n\nSince 1.51, the below syntax is valid:\n\n```rust\nstruct Foo\u003cconst N: usize\u003e {\n    data: [i32; N],\n}\n```\n\nHowever, the const-generics we have as of writing this are still the minimum-viable product (`min_const_generics`), so many situations still result in errors, such as this example:\n\n```rust\ntrait Bar {\n    const LEN: usize;\n\n    // Error: cannot perform const operation using `Self`\n    fn bar(\u0026self) -\u003e Foo\u003c{ Self::LEN }\u003e;\n}\n```\n\n**generic-array** defines a new trait `ArrayLength` and a struct `GenericArray\u003cT, N: ArrayLength\u003e`, which lets the above be implemented as:\n\n```rust\nstruct Foo\u003cN: ArrayLength\u003e {\n    data: GenericArray\u003ci32, N\u003e\n}\n\ntrait Bar {\n    type LEN: ArrayLength;\n    fn bar(\u0026self) -\u003e Foo\u003cSelf::LEN\u003e;\n}\n```\n\nThe `ArrayLength` trait is implemented for [unsigned integer types](http://fizyk20.github.io/generic-array/typenum/uint/index.html) from [typenum](http://fizyk20.github.io/generic-array/typenum/index.html) crate. For example, `GenericArray\u003cT, U5\u003e` would work almost like `[T; 5]`:\n\n```rust\nuse generic_array::typenum::U5;\n\nstruct Foo\u003cT, N: ArrayLength\u003e {\n    data: GenericArray\u003cT, N\u003e\n}\n\nlet foo = Foo::\u003ci32, U5\u003e { data: GenericArray::default() };\n```\n\nThe `arr!` macro is provided to allow easier creation of literal arrays, as shown below:\n\n```rust\nlet array = arr![1, 2, 3];\n//  array: GenericArray\u003ci32, typenum::U3\u003e\nassert_eq!(array[2], 3);\n```\n\n## Feature flags\n\n```toml\n[dependencies.generic-array]\nfeatures = [\n    \"serde\",         # Serialize/Deserialize implementation\n    \"zeroize\",       # Zeroize implementation for setting array elements to zero\n    \"const-default\", # Compile-time const default value support via trait\n    \"alloc\",         # Enables From/TryFrom implementations between GenericArray and Vec\u003cT\u003e/Box\u003c[T]\u003e\n    \"faster-hex\"     # Enables internal use of the `faster-hex` crate for faster hex encoding via SIMD\n]\n```","funding_links":[],"categories":["Libraries","Rust","库 Libraries","库"],"sub_categories":["Data structures","数据结构 Data structures","数据结构"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffizyk20%2Fgeneric-array","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffizyk20%2Fgeneric-array","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffizyk20%2Fgeneric-array/lists"}