{"id":23745278,"url":"https://github.com/ilyvion/nombytes","last_synced_at":"2025-12-12T14:03:36.853Z","repository":{"id":49372078,"uuid":"517155356","full_name":"ilyvion/nombytes","owner":"ilyvion","description":"nombytes is a library that provides a wrapper for the bytes::Bytes byte container for use with nom.","archived":false,"fork":false,"pushed_at":"2022-08-01T10:38:35.000Z","size":1335,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-14T19:11:23.540Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ilyvion.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":"ilyvion","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2022-07-23T20:13:26.000Z","updated_at":"2022-07-25T10:46:40.000Z","dependencies_parsed_at":"2022-09-04T00:21:08.536Z","dependency_job_id":null,"html_url":"https://github.com/ilyvion/nombytes","commit_stats":null,"previous_names":["ilyvion/nombytes","alexschrod/nombytes"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilyvion%2Fnombytes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilyvion%2Fnombytes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilyvion%2Fnombytes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilyvion%2Fnombytes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ilyvion","download_url":"https://codeload.github.com/ilyvion/nombytes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239898456,"owners_count":19715212,"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":[],"created_at":"2024-12-31T12:57:01.654Z","updated_at":"2025-11-11T11:36:38.663Z","avatar_url":"https://github.com/ilyvion.png","language":"Rust","funding_links":["https://ko-fi.com/ilyvion"],"categories":[],"sub_categories":[],"readme":"# NomBytes\n\n[![Crates.io](https://img.shields.io/crates/v/nombytes)](https://crates.io/crates/nombytes)\n[![Crates.io](https://img.shields.io/crates/l/nombytes)](https://crates.io/crates/nombytes)\n[![Crates.io](https://img.shields.io/crates/d/nombytes)](https://crates.io/crates/nombytes)\n[![Docs.io](https://docs.rs/nombytes/badge.svg)](https://docs.rs/nombytes)\n[![Docs master](https://img.shields.io/static/v1?label=docs\u0026message=master\u0026color=5479ab)](https://alexschrod.github.io/nombytes/)\n[![Rust](https://github.com/alexschrod/nombytes/actions/workflows/CI.yml/badge.svg)](https://github.com/alexschrod/nombytes/actions/workflows/CI.yml)\n[![codecov](https://codecov.io/gh/alexschrod/nombytes/branch/master/graph/badge.svg?token=HHJWVMF7GS)](https://codecov.io/gh/alexschrod/nombytes)\n[![Codacy](https://app.codacy.com/project/badge/Grade/a77f961673f646fab6aa6d82b8d73050)](https://www.codacy.com/gh/alexschrod/nombytes/dashboard?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=alexschrod/nombytes\u0026amp;utm_campaign=Badge_Grade)\n\n`nombytes` is a library that provides a wrapper for the `bytes::Bytes` byte\ncontainer for use with nom.\n\nI originally made this so that I could have a function take a file name path\nand return parsed values that still had references to the loaded file without\nrunning into the lifetime issues associated with `\u0026[u8]` and `\u0026str` that\nwould prevent me from doing so. I decided to release it as a crate so that\nothers can make use of my efforts too.\n\nThis library has been tested to work with `bytes` down to v5.3.0 and `nom` down\nto v6.0.0 and has been marked as such in its `Cargo.toml`.\n\n## Usage\n\nPut this in your `Cargo.toml`:\n\n```toml\n[dependencies]\nnombytes = \"0.1.1\"\n```\n\n## Features\n\n### `miette`\n\nWith the `miette` feature enabled, the `NomBytes` implements its\n`SourceCode` trait so it can be used directly with `miette`'s\n`#[source_code]` error attribute. This feature also enables the `std`\nfeature.\n\nThis library has been tested to work with `miette` down to v3.0.0 and\nhas been marked as such in its `Cargo.toml`.\n\n### `serde`\n\nAdds `serde::Serialize` and `serde::Deserialize` implementations to the types\nin this library to allow for using them with `serde`.\n\n### `std`\n\nEnabled by default; allows creating `NomBytes` directly from `String`s\nthrough a `From\u003cString\u003e` impl. With this feature turned off, this crate\nis `#![no_std]` compatible.\n\n## Example\n\nBorrowed from the `nom` crate, using `NomBytes` instead of `\u0026str`. Had to be\nmodified slightly because `NomBytes` acts as `\u0026[u8]` rather than as `\u0026str`.\n\n```rust\nuse nom::{\n  IResult,\n  bytes::complete::{tag, take_while_m_n},\n  combinator::map_res,\n  sequence::tuple};\nuse nombytes::NomBytes;\n\n#[derive(Debug,PartialEq)]\npub struct Color {\n  pub red:     u8,\n  pub green:   u8,\n  pub blue:    u8,\n}\n\nfn from_hex(input: NomBytes) -\u003e Result\u003cu8, std::num::ParseIntError\u003e {\n  u8::from_str_radix(input.to_str(), 16)\n}\n\nfn is_hex_digit(c: u8) -\u003e bool {\n  (c as char).is_digit(16)\n}\n\nfn hex_primary(input: NomBytes) -\u003e IResult\u003cNomBytes, u8\u003e {\n  map_res(\n    take_while_m_n(2, 2, is_hex_digit),\n    from_hex\n  )(input)\n}\n\nfn hex_color(input: NomBytes) -\u003e IResult\u003cNomBytes, Color\u003e {\n  let (input, output) = tag(\"#\")(input)?;\n\n  let (input, (red, green, blue)) = tuple((hex_primary, hex_primary, hex_primary))(input)?;\n\n  Ok((input, Color { red, green, blue }))\n}\n\nfn main() {\n  assert!(matches!(hex_color(NomBytes::from(\"#2F14DF\")),\n    Ok((r, Color {\n      red: 47,\n      green: 20,\n      blue: 223,\n    })) if r.to_str() == \"\"));\n}\n```\n\n## License\n\nLicensed under either of\n\n-   Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or \u003chttp://www.apache.org/licenses/LICENSE-2.0\u003e)\n-   MIT license ([LICENSE-MIT](LICENSE-MIT) or \u003chttp://opensource.org/licenses/MIT\u003e)\n\nat your option.\n\n### Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be\ndual licensed as above, without any additional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filyvion%2Fnombytes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Filyvion%2Fnombytes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filyvion%2Fnombytes/lists"}