{"id":16376660,"url":"https://github.com/udoprog/bittle","last_synced_at":"2026-03-11T01:32:06.857Z","repository":{"id":57515299,"uuid":"439012107","full_name":"udoprog/bittle","owner":"udoprog","description":"Zero-cost bitsets over native Rust types","archived":false,"fork":false,"pushed_at":"2025-03-29T10:58:22.000Z","size":191,"stargazers_count":77,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-08T21:17:18.334Z","etag":null,"topics":["bitset","rust"],"latest_commit_sha":null,"homepage":"","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/udoprog.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-12-16T14:08:50.000Z","updated_at":"2025-05-07T02:42:19.000Z","dependencies_parsed_at":"2024-03-03T15:32:10.616Z","dependency_job_id":"60f21ec7-7c29-4268-a147-79c6d1fc3e6c","html_url":"https://github.com/udoprog/bittle","commit_stats":{"total_commits":74,"total_committers":2,"mean_commits":37.0,"dds":"0.027027027027026973","last_synced_commit":"0716b31c61dfba01b28fe2d387f4e76ebc1cedc1"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/udoprog/bittle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udoprog%2Fbittle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udoprog%2Fbittle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udoprog%2Fbittle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udoprog%2Fbittle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/udoprog","download_url":"https://codeload.github.com/udoprog/bittle/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/udoprog%2Fbittle/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30366051,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T21:41:54.280Z","status":"ssl_error","status_checked_at":"2026-03-10T21:40:59.357Z","response_time":106,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["bitset","rust"],"created_at":"2024-10-11T03:25:36.766Z","updated_at":"2026-03-11T01:32:06.840Z","avatar_url":"https://github.com/udoprog.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bittle\n\n[\u003cimg alt=\"github\" src=\"https://img.shields.io/badge/github-udoprog/bittle-8da0cb?style=for-the-badge\u0026logo=github\" height=\"20\"\u003e](https://github.com/udoprog/bittle)\n[\u003cimg alt=\"crates.io\" src=\"https://img.shields.io/crates/v/bittle.svg?style=for-the-badge\u0026color=fc8d62\u0026logo=rust\" height=\"20\"\u003e](https://crates.io/crates/bittle)\n[\u003cimg alt=\"docs.rs\" src=\"https://img.shields.io/badge/docs.rs-bittle-66c2a5?style=for-the-badge\u0026logoColor=white\u0026logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K\" height=\"20\"\u003e](https://docs.rs/bittle)\n[\u003cimg alt=\"build status\" src=\"https://img.shields.io/github/actions/workflow/status/udoprog/bittle/ci.yml?branch=main\u0026style=for-the-badge\" height=\"20\"\u003e](https://github.com/udoprog/bittle/actions?query=branch%3Amain)\n\nZero-cost bitsets over native Rust types.\n\nThe name `bittle` comes from `bit` and `little`. Small bitsets!\n\n\u003cbr\u003e\n\n## Usage\n\nAdd `bittle` as a dependency in your `Cargo.toml`:\n\n\u003cbr\u003e\n\n```toml\n[dependencies]\nbittle = \"0.6.0\"\n```\n\n\u003cbr\u003e\n\n## Guide\n\nA bit is always identified by a [`u32`] by its index, and the exact location\nfor a bit in a primitive numbers is defined by its endianness, which is\n[`BigEndian`] by default.\n\n[`BigEndian`] indexing grows from right to left, such as the following\n[`u8`] literal:\n\n```text\n0b0010_0010u8\n    ^    ^- index 1\n    '------ index 5\n```\n\n\u003cbr\u003e\n\nTo interact with these bits we define the [`Bits`], [`BitsMut`], and\n[`BitsOwned`] traits. These traits are implemented for primitive types such\nas `u32`, `[u32; 4]`, or `\u0026[u32]`:\n\n```rust\nuse bittle::Bits;\n\nlet array: [u32; 4] = [0, 1, 2, 3];\nassert!(array.iter_ones().eq([32, 65, 96, 97]));\n\nlet n = 0b00000000_00000000_00000000_00010001u32;\nassert!(n.iter_ones().eq([0, 4]));\n\nlet array_of_arrays: [[u8; 4]; 2] = [[16, 0, 0, 0], [0, 0, 1, 0]];\nassert!(array_of_arrays.iter_ones().eq([4, 48]));\n\nlet mut vec: Vec\u003cu32\u003e = vec![0, 1, 2, 3];\nassert!(vec.iter_ones().eq([32, 65, 96, 97]));\n```\n\n\u003cbr\u003e\n\nWe also provide the [`set!`] macro, which is a zero-cost convenience method\nfor constructing primitive forms of bit sets:\n\n```rust\nuse bittle::Bits;\n\nlet array: [u32; 4] = bittle::set![32, 65, 96, 97];\nassert!(array.iter_ones().eq([32, 65, 96, 97]));\n\nlet n: u32 = bittle::set![0, 4];\nassert!(n.iter_ones().eq([0, 4]));\n\nlet array_of_arrays: [[u8; 4]; 2] = bittle::set![4, 48];\nassert!(array_of_arrays.iter_ones().eq([4, 48]));\n```\n\n\u003cbr\u003e\n\nSince a vector is not a primitive bit set, it could instead make use of\n[`BitsMut`] directly:\n\n```rust\nuse bittle::{Bits, BitsMut};\n\nlet mut vec: Vec\u003cu32\u003e = vec![0u32; 4];\nvec.set_bit(32);\nvec.set_bit(65);\nvec.set_bit(96);\nvec.set_bit(97);\nassert!(vec.iter_ones().eq([32, 65, 96, 97]));\nassert_eq!(vec, [0, 1, 2, 3]);\n```\n\n\u003cbr\u003e\n\nDue to how broadly these traits are implemented, we also try to avoid using\nnames which are commonly used in other APIs, instead opt for bit-specific\nterminology such as:\n\n* Something like `is_empty` becomes `all_zeros` - since with bits you're\n  thinking about \"ones and zeros\".\n* Testing if a bit is set is `test_bit`, or in general adding the `*_bit`\n  suffix to operations over individual bits.\n* Clearing all bits becomes `clear_bits`, or in general adding the `*_bits`\n  suffix when operating over *all* bits.\n\n```rust\nuse bittle::{Bits, BitsMut};\n\nlet mut set = [0u16; 2];\n\nset.set_bit(15);\nassert!(set.test_bit(15));\n\nset.union_assign(\u0026bittle::set![31, 7]);\nassert!(set.test_bit(31) \u0026\u0026 set.test_bit(7));\n\nset.clear_bit(31);\nassert!(!set.test_bit(31));\n\nset.clear_bits();\nassert!(set.all_zeros());\n```\n\n\u003cbr\u003e\n\nSome other interesting operations, such as [`Bits::join_ones`] are available,\nallowing bitsets to act like masks over other iterators:\n\n```rust\nuse bittle::{Bits, BitsMut};\n\nlet elements = vec![10, 48, 101];\nlet mut m = 0u128;\n\nm.set_bit(0);\nassert!(m.join_ones(\u0026elements).eq([\u002610]));\nm.set_bit(2);\nassert!(m.join_ones(\u0026elements).eq([\u002610, \u0026101]));\n```\n\n\u003cbr\u003e\n\n[`BigEndian`]: https://docs.rs/bittle/latest/bittle/struct.BigEndian.html\n[`Bits::join_ones`]: https://docs.rs/bittle/latest/bittle/trait.Bits.html#method.join_ones\n[`Bits::test_bit_in`]: https://docs.rs/bittle/latest/bittle/trait.Bits.html#method.test_bit_in\n[`Bits::test_bit_le`]: https://docs.rs/bittle/latest/bittle/trait.Bits.html#method.test_bit_le\n[`Bits`]: https://docs.rs/bittle/latest/bittle/trait.Bits.html\n[`BitsMut`]: https://docs.rs/bittle/latest/bittle/trait.BitsMut.html\n[`BitsOwned`]: https://docs.rs/bittle/latest/bittle/trait.BitsOwned.html\n[`Copy`]: https://doc.rust-lang.org/std/marker/trait.Copy.html\n[`set!`]: https://docs.rs/bittle/latest/bittle/macro.set.html\n[`u32`]: https://doc.rust-lang.org/std/primitive.u32.html\n[`u8`]: https://doc.rust-lang.org/std/primitive.u8.html\n[see issue #2]: https://github.com/udoprog/bittle/pull/2\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fudoprog%2Fbittle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fudoprog%2Fbittle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fudoprog%2Fbittle/lists"}