{"id":22292632,"url":"https://github.com/rustyyato/vec-utils","last_synced_at":"2025-12-12T14:37:09.300Z","repository":{"id":56469725,"uuid":"206916628","full_name":"RustyYato/vec-utils","owner":"RustyYato","description":null,"archived":false,"fork":false,"pushed_at":"2020-11-05T14:50:49.000Z","size":121,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-05T05:23:29.432Z","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":"2019-09-07T04:43:10.000Z","updated_at":"2024-02-25T21:19:38.000Z","dependencies_parsed_at":"2022-08-15T19:20:36.219Z","dependency_job_id":null,"html_url":"https://github.com/RustyYato/vec-utils","commit_stats":null,"previous_names":["krishnasannasi/vec-utils"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/RustyYato/vec-utils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RustyYato%2Fvec-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RustyYato%2Fvec-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RustyYato%2Fvec-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RustyYato%2Fvec-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RustyYato","download_url":"https://codeload.github.com/RustyYato/vec-utils/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RustyYato%2Fvec-utils/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:13.442Z","updated_at":"2025-10-19T01:15:49.719Z","avatar_url":"https://github.com/RustyYato.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vec-utils\n\nThis is an experimental crate that adds some helpful functionality to `Vec\u003cT\u003e`, like `map` and `zip_with`. These functions allow you to transform a vec and try and reuse the allocation if possible!\n\n```rust\nuse vec_utils::VecExt;\n\nfn to_bits(v: Vec\u003cf32\u003e) -\u003e Vec\u003cu32\u003e {\n    v.map(|x| x.to_bits())\n}\n\nfn sum_2(v: Vec\u003cf32\u003e, w: Vec\u003cf64\u003e) -\u003e Vec\u003cf64\u003e {\n    v.zip_with(w, |x, y| f64::from(x) + y)\n}\n```\n\nBut `zip_with` is limited to taking only a single additional vector. To get around this limitation, this crate also exports some macros that can take an arbitrary number of input vectors, and in most cases will compile down to the same assembly as `Vec::map` and `Vec::zip_with` (sometimes with some additional cleanup code, but even then the macro solution is just as fast as the built-in version).\n\nYou can use the `zip_with` and `try_zip_with` macros like so,\n\n```rust\nuse vec_utils::{zip_with, try_zip_with};\n\nfn to_bits(v: Vec\u003cf32\u003e) -\u003e Vec\u003cu32\u003e {\n    zip_with!(v, |x| x.to_bits())\n}\n\nfn sum_2(v: Vec\u003cf32\u003e, w: Vec\u003cf64\u003e) -\u003e Vec\u003cf64\u003e {\n    zip_with!((v, w), |x, y| f64::from(x) + y)\n}\n\nfn sum_5(a: Vec\u003ci32\u003e, b: Vec\u003ci32\u003e, c: Vec\u003ci32\u003e, d: Vec\u003ci32\u003e, e: Vec\u003ci32\u003e) -\u003e Vec\u003ci32\u003e {\n    zip_with!((a, b, c, d, e), |a, b, c, d, e| a + b + c + d + e)\n}\n\nfn mul_with(a: Vec\u003ci32\u003e) -\u003e Vec\u003ci32\u003e {\n    zip_with!((a, vec![0, 1, 2, 3, 4, 5, 6, 7]), |a, x| a * x)\n}\n\nfn to_bits_no_nans(v: Vec\u003cf32\u003e) -\u003e Result\u003cVec\u003cu32\u003e, \u0026'static str\u003e {\n    try_zip_with!(v, |x| if x.is_nan() { Err(\"Found NaN!\") } else { Ok(x.to_bits()) })\n}\n```\n\nYou can use as many input vectors as you want, just put them all inside the input tuple. Note that the second argument is not a closure, but syntax that looks like a closure, i.e. you can't make a closure before-hand and pass it as the second argument. Also, you can't use general patterns in the \"closure\"'s arguments, only identifiers are allowed. You can specify if you want a move closure by adding the move keyword in from of the \"closure\".\n\n```rust\nuse vec_utils::zip_with;\n\nfn add(a: Vec\u003ci32\u003e, b: i32) -\u003e Vec\u003ci32\u003e {\n    zip_with!(a, move |a| a + b)\n}\n```\n\nIt also adds some functionality to reuse the allocation of a `Box\u003cT\u003e`, using the `BoxExt`/`UninitBox` api.\n\n```rust\nuse vec_utils::BoxExt;\n\nfn replace(b: Box\u003ci32\u003e, f: f32) -\u003e Box\u003cf32\u003e {\n    Box::drop_box(b).init(f)\n}\n\nfn get_and_replace(b: Box\u003ci32\u003e, f: f32) -\u003e (Box\u003cf32\u003e, i32) {\n    let (b, x) = Box::take_box(b);\n    (b.init(f), x)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frustyyato%2Fvec-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frustyyato%2Fvec-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frustyyato%2Fvec-utils/lists"}