{"id":22292628,"url":"https://github.com/rustyyato/generic-vec","last_synced_at":"2025-09-25T12:31:34.334Z","repository":{"id":55989432,"uuid":"315707023","full_name":"RustyYato/generic-vec","owner":"RustyYato","description":null,"archived":false,"fork":false,"pushed_at":"2021-04-09T14:37:57.000Z","size":359,"stargazers_count":19,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-06-23T09:18:04.273Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RustyYato.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-24T17:34:55.000Z","updated_at":"2023-06-18T09:50:34.000Z","dependencies_parsed_at":"2022-08-15T10:50:58.339Z","dependency_job_id":null,"html_url":"https://github.com/RustyYato/generic-vec","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/RustyYato/generic-vec","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RustyYato%2Fgeneric-vec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RustyYato%2Fgeneric-vec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RustyYato%2Fgeneric-vec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RustyYato%2Fgeneric-vec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RustyYato","download_url":"https://codeload.github.com/RustyYato/generic-vec/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RustyYato%2Fgeneric-vec/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267604324,"owners_count":24114522,"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","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-03T17:23:12.411Z","updated_at":"2025-09-25T12:31:34.267Z","avatar_url":"https://github.com/RustyYato.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Crates.io](https://img.shields.io/crates/v/generic-vec.svg)](https://crates.io/crates/generic-vec)\n[![Docs.rs](https://docs.rs/generic-vec/badge.svg)](https://docs.rs/generic-vec)\n[![Workflow Status](https://github.com/rustyyato/generic-vec/workflows/main/badge.svg)](https://github.com/rustyyato/generic-vec/actions?query=workflow%3A%22main%22)\n![Maintenance](https://img.shields.io/badge/maintenance-activly--developed-brightgreen.svg)\n\n# generic-vec\n\nA vector that can store items anywhere: in slices, arrays, or the heap!\n\n`GenericVec` has complete parity with `Vec`, and even provides some features\nthat are only in `nightly` on `std` (like `GenericVec::drain_filter`), or a more permissive\ninterface like `GenericVec::retain`. In fact, you can trivially convert a `Vec` to a\n`HeapVec` and back!\n\nThis crate is `no_std` compatible, just turn off all default features.\n\n## Features\n\n* `std` (default) - enables you to use an allocator, and\n* `alloc` - enables you to use an allocator, for heap allocated storages\n    (like `Vec`)\n* `nightly` - enables you to use array (`[T; N]`) based storages\n\n## Basic Usage\n\n#### `SliceVec` and `InitSliceVec`\n\n`SliceVec` and `InitSliceVec` are pretty similar, you give them a slice\nbuffer, and they store all of thier values in that buffer. But have three major\ndifferences between them.\n\n* You can pass an uninitialized buffer to `SliceVec`\n* You can only use `Copy` types with `InitSliceVec`\n* You can freely set the length of the `InitSliceVec` as long as you stay\n    within it's capacity (the length of the slice you pass in)\n\n```rust\nuse generic_vec::{SliceVec, InitSliceVec, uninit_array};\n\nlet mut uninit_buffer = uninit_array!(16);\nlet mut slice_vec = SliceVec::new(\u0026mut uninit_buffer);\n\nassert!(slice_vec.is_empty());\nslice_vec.push(10);\nassert_eq!(slice_vec, [10]);\n```\n\n```rust\nlet mut init_buffer = [0xae; 16];\nlet mut slice_vec = InitSliceVec::new(\u0026mut init_buffer);\n\nassert!(slice_vec.is_full());\nassert_eq!(slice_vec.pop(), 0xae);\nslice_vec.set_len(16);\nassert!(slice_vec.is_full());\n```\n\nOf course if you try to push past a `*SliceVec`'s capacity\n(the length of the slice you passed in), then it will panic.\n\n```rust\nlet mut init_buffer = [0xae; 16];\nlet mut slice_vec = InitSliceVec::new(\u0026mut init_buffer);\nslice_vec.push(0);\n```\n\n#### `TypeVec`\n\n`TypeVec` is an owned buffer. You can use like so:\n\n```rust\nuse generic_vec::{TypeVec, gvec};\nlet mut vec: TypeVec\u003cu32, [u32; 4]\u003e = gvec![1, 2, 3, 4];\n\nassert_eq!(vec, [1, 2, 3, 4]);\n\nvec.try_push(5).expect_err(\"Tried to push past capacity!\");\n```\n\nThe second parameter specifies the buffer type, this can be any type\nyou want. Only the size of the type matters. There is also a defaulted\nthird parameter, but you should only use that if you know what you are\ndoing, and after reading the docs for `UninitBuffer`.\n\nAs a neat side-effect of this framework, you can also get an efficient\n`GenericVec` for zero-sized types, just a `usize` in size! This feature\ncan be on stable `no_std`.\n\n#### `ArrayVec` and `InitArrayVec`\n\n`ArrayVec` and `InitArrayVec`\nare just like the slice versions, but since they own their data,\nthey can be freely moved around, unconstrained. You can also create\na new `ArrayVec` without passing in an existing buffer,\nunlike the slice versions.\n\nOn stable, you can use the `ArrayVec` or\n`InitArrayVec` to construct the type. On `nightly`,\nyou can use the type aliases `ArrayVec` and\n`InitArrayVec`. The macros will be deprecated once\n`min_const_generics` hits stable.\n\nThe only limitation on stable is that you can only use `InitArrayVec`\ncapacity up to 32. i.e. `InitArrayVec![i32; 33]` doesn't work. `ArrayVec` does not suffer\nfrom this limitation because it is built atop `TypeVec`.\n\n```rust\nuse generic_vec::ArrayVec;\n\nlet mut array_vec = ArrayVec::\u003ci32, 16\u003e::new();\n\narray_vec.push(10);\narray_vec.push(20);\narray_vec.push(30);\n\nassert_eq!(array_vec, [10, 20, 30]);\n```\n\nThe distinction between `ArrayVec` and `InitArrayVec`\nis identical to their slice counterparts.\n\n#### `ZSVec`\n\n```rust\nuse generic_vec::ZSVec;\n\nstruct MyType;\n\nlet mut vec = ZSVec::new();\n\nvec.push(MyType);\nvec.push(MyType);\nvec.push(MyType);\n\nassert_eq!(vec.len(), 3);\nassert_eq!(std::mem::size_of_val(\u0026vec), std::mem::size_of::\u003cusize\u003e());\n```\n\n### `alloc`\n\nA `HeapVec` is just `Vec`, but built atop `GenericVec`,\nmeaning you get all the features of `GenericVec` for free! But this\nrequries either the `alloc` or `std` feature to be enabled.\n\n```rust\nuse generic_vec::{HeapVec, gvec};\nlet mut vec: HeapVec\u003cu32\u003e = gvec![1, 2, 3, 4];\nassert_eq!(vec.capacity(), 4);\nvec.extend(\u0026[5, 6, 7, 8]);\n\nassert_eq!(vec, [1, 2, 3, 4, 5, 6, 7, 8]);\n\nvec.try_push(5).expect_err(\"Tried to push past capacity!\");\n```\n\n### `nightly`\n\nOn `nightly`\n* the restriction on `InitArrayVec`'s length goes away.\n* many functions/methods become `const fn`s\n* a number of optimizations are enabled\n* some diagnostics become better\n\nNote on the documentation: if the feature exists on `Vec`, then the documentation\nis either exactly the same as `Vec` or slightly adapted to better fit `GenericVec`\n\nNote on implementation: large parts of the implementation came straight from `Vec`\nso thanks for the amazing reference `std`!\n\nCurrent version: 0.1.2\n\nLicense: MIT/Apache-2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frustyyato%2Fgeneric-vec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frustyyato%2Fgeneric-vec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frustyyato%2Fgeneric-vec/lists"}