{"id":13437337,"url":"https://github.com/whitfin/bytelines","last_synced_at":"2025-04-09T20:09:08.604Z","repository":{"id":62438716,"uuid":"161841011","full_name":"whitfin/bytelines","owner":"whitfin","description":"Read input lines as byte slices for high efficiency","archived":false,"fork":false,"pushed_at":"2024-01-05T21:43:38.000Z","size":40,"stargazers_count":64,"open_issues_count":3,"forks_count":9,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-09T20:09:03.258Z","etag":null,"topics":["algorithms","memory-efficiency","performance","text-processing"],"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/whitfin.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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-12-14T21:13:00.000Z","updated_at":"2025-03-18T22:59:51.000Z","dependencies_parsed_at":"2023-02-09T09:35:18.016Z","dependency_job_id":"7d1eb157-ec06-4edb-8dc3-a3a21bed8f6e","html_url":"https://github.com/whitfin/bytelines","commit_stats":{"total_commits":30,"total_committers":2,"mean_commits":15.0,"dds":"0.033333333333333326","last_synced_commit":"ef627d12374e1c3577287ea871676d715afae491"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whitfin%2Fbytelines","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whitfin%2Fbytelines/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whitfin%2Fbytelines/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whitfin%2Fbytelines/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/whitfin","download_url":"https://codeload.github.com/whitfin/bytelines/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103872,"owners_count":21048245,"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":["algorithms","memory-efficiency","performance","text-processing"],"created_at":"2024-07-31T03:00:56.088Z","updated_at":"2025-04-09T20:09:08.585Z","avatar_url":"https://github.com/whitfin.png","language":"Rust","funding_links":[],"categories":["Applications","应用程序 Applications","应用","应用 Applications"],"sub_categories":["Text processing","文本处理 Text processing","文本处理"],"readme":"# bytelines\n[![Build Status](https://img.shields.io/github/actions/workflow/status/whitfin/bytelines/ci.yml)](https://github.com/whitfin/bytelines/actions)\n[![Crates.io](https://img.shields.io/crates/v/bytelines.svg)](https://crates.io/crates/bytelines)\n\nThis library provides an easy way to read in input lines as byte slices for high efficiency. It's basically [lines](https://doc.rust-lang.org/std/io/trait.BufRead.html#method.lines) from the standard library, but it reads each line as a byte slice (`\u0026[u8]`). This performs significantly faster than `lines()` in the case you don't particularly care about unicode, and basically as fast as writing the loops out by hand. Although the code itself is somewhat trivial, I've had to roll this in at least 4 tools I've written recently and so I figured it was time to have a convenience crate for it.\n\n### Installation\n\nThis tool will be available via [Crates.io](https://crates.io/crates/bytelines), so you can add it as a dependency in your `Cargo.toml`:\n\n```toml\n[dependencies]\nbytelines = \"2.5\"\n```\n\n### Usage\n\nIt's quite simple; in the place you would typically call `lines` on a `BufRead` implementor, you can now use `bytelines` to retrieve a structure used to walk over lines as `\u0026[u8]` (and thus avoid allocations). There are two ways to use the API, and both are shown below:\n\n```rust\n// our input file we're going to walk over lines of, and our reader\nlet file = File::open(\"./my-input.txt\").expect(\"able to open file\");\nlet reader = BufReader::new(file);\nlet mut lines = ByteLines::new(reader);\n\n// Option 1: Walk using a `while` loop.\n//\n// This is the most performant option, as it avoids an allocation by\n// simply referencing bytes inside the reading structure. This means\n// that there's no copying at all, until the developer chooses to.\nwhile let Some(line) = lines.next() {\n    // do something with the line\n}\n\n// Option 2: Use the `Iterator` trait.\n//\n// This is more idiomatic, but requires allocating each line into\n// an owned `Vec` to avoid potential memory safety issues. Although\n// there is an allocation here, the overhead should be negligible\n// except in cases where performance is paramount.\nfor line in lines.into_iter() {\n    // do something with the line\n}\n```\n\nAs of v2.3 this crate includes fairly minimal support for Tokio, namely the `AsyncBufRead` trait. This looks fairly similar to the base APIs, and can be used in much the same way.\n\n\n```rust\n// configure our inputs again, using `AsyncByteLines`.\nlet file = File::open(\"./my-input.txt\").await?;\nlet reader = BufReader::new(file);\nlet mut lines = AsyncByteLines::new(reader);\n\n// walk through all lines using a `while` loop\nwhile let Some(line) = lines.next().await? {\n    // do something with the line\n}\n\n// walk through all lines using `Stream` APIs\nlines.into_stream().for_each(|line| {\n\n});\n```\n\nThe main difference is that the Tokio implementations yield `Result\u003cOption\u003c\u0026[u8]\u003e, _\u003e` instead of `Option\u003cResult\u003c\u0026[u8], _\u003e\u003e` for consistency with the exiting Tokio APIs. If you don't want Tokio support, please disable default features:\n\n```toml\n[dependencies]\nbytelines = { version = \"2.5\", default-features = false }\n```\n\nThis will be removed as a default feature in the next major bump (v3.0), but for now you can exclude it this way.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhitfin%2Fbytelines","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwhitfin%2Fbytelines","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhitfin%2Fbytelines/lists"}