{"id":13822444,"url":"https://github.com/avitex/rust-dangerous","last_synced_at":"2025-06-28T08:34:52.122Z","repository":{"id":45113603,"uuid":"283795549","full_name":"avitex/rust-dangerous","owner":"avitex","description":"Rust library for safely and explicitly parsing untrusted data","archived":false,"fork":false,"pushed_at":"2024-05-03T10:02:09.000Z","size":1099,"stargazers_count":51,"open_issues_count":5,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-10T05:24:57.232Z","etag":null,"topics":["no-std","parsing","rust-lang"],"latest_commit_sha":null,"homepage":"","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/avitex.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,"publiccode":null,"codemeta":null}},"created_at":"2020-07-30T14:20:58.000Z","updated_at":"2024-09-12T09:52:00.000Z","dependencies_parsed_at":"2024-08-04T08:08:27.495Z","dependency_job_id":"9845f5f0-e56a-4fd6-896a-f36abf33d313","html_url":"https://github.com/avitex/rust-dangerous","commit_stats":{"total_commits":451,"total_committers":3,"mean_commits":"150.33333333333334","dds":0.09312638580931265,"last_synced_commit":"107b92f6ea41c3c9fbdd258680482074ac7384a5"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avitex%2Frust-dangerous","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avitex%2Frust-dangerous/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avitex%2Frust-dangerous/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avitex%2Frust-dangerous/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/avitex","download_url":"https://codeload.github.com/avitex/rust-dangerous/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230507051,"owners_count":18236944,"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":["no-std","parsing","rust-lang"],"created_at":"2024-08-04T08:02:00.506Z","updated_at":"2024-12-19T22:07:49.182Z","avatar_url":"https://github.com/avitex.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"[![Build Status](https://github.com/avitex/rust-dangerous/workflows/build/badge.svg)](https://github.com/avitex/rust-dangerous/actions?query=workflow:build)\n[![Coverage Status](https://codecov.io/gh/avitex/rust-dangerous/branch/master/graph/badge.svg?token=X2LXHI8VYL)](https://codecov.io/gh/avitex/rust-dangerous)\n[![Crate](https://img.shields.io/crates/v/dangerous.svg)](https://crates.io/crates/dangerous)\n[![Docs](https://docs.rs/dangerous/badge.svg)](https://docs.rs/dangerous)\n\n# rust-dangerous\n\n**Rust library for safely and explicitly handling untrusted aka `dangerous` data**  \nDocumentation hosted on [docs.rs](https://docs.rs/dangerous).\n\n```toml\ndangerous = \"0.10\"\n```\n\n## Goals\n\n- Fast parsing.\n- Fast to compile.\n- Zero panics \\[1].\n- Zero-cost abstractions.\n- Minimal dependencies \\[2].\n- Retry/stream protocol support.\n- `no-std` / suitable for embedded.\n- Zero heap-allocations on success paths \\[3].\n- Primitive type support.\n- Optional verbose errors.\n- Optional SIMD optimisations where possible.\n\n**\\[1]** Panics due to OOM are out-of-scope. Disable heap-allocations if this is\na concern.  \n**\\[2]** Zero dependencies when both `unicode` and `simd` features are disabled.  \n**\\[3]** Zero heap-allocations when the `full-backtrace` feature is disabled.\n\nThis library's intentions are to provide a simple interface for explicitly\nparsing untrusted data safely. `dangerous` really shines with parsing binary or\nsimple text data formats and protocols. It is not a deserialisation library like\nwhat `serde` provides, but you could write a parser with `dangerous` that could\nbe used within a deserialiser.\n\nPanics and unhandled/unacknowledged data are two footguns this library seeks to\nprevent. An optional, but solid, debugging interface with sane input formatting\nand helpful errors is included to weed out problems before, or after they arise\nin production.\n\n## Usage\n\n```rust\nfn decode_message\u003c'i, E\u003e(r: \u0026mut BytesReader\u003c'i, E\u003e) -\u003e Result\u003cMessage\u003c'i\u003e, E\u003e\nwhere\n    E: Error\u003c'i\u003e,\n{\n    r.context(\"message\", |r| {\n        // Expect version 1\n        r.context(\"version\", |r| r.consume(0x01))?;\n        // Read the body length\n        let body_len = r.context(\"body len\", |r| r.read())?;\n        // Take the body input\n        let body = r.context(\"body\", |r| {\n            let body_input = r.take(body_len as usize)?;\n            // Decode the body input as a UTF-8 str\n            body_input.to_dangerous_str()\n        })?;\n        // We did it!\n        Ok(Message { body })\n    })\n}\n\nlet input = dangerous::input(/* data */);\nlet result: Result\u003c_, Invalid\u003e = input.read_all(decode_message);\n```\n\n## Errors\n\nCustom errors for protocols often do not provide much context around why and\nwhere a specific problem occurs within input. Passing down errors as simple as\n`core::str::Utf8Error` may be useful enough to debug while in development,\nhowever when just written into logs without the input/context, often amount to\nnoise. At this stage you are almost better off with a simple input error.\n\nThis problem is amplified with any trivial recursive-descent parser as the\ncontext around a sub-slice is lost, rendering any error offsets useless when\npassed back up to the root. `dangerous` fixes this by capturing the context\naround and above the error.\n\nEver tried working backwards from something like this?\n\n```\n[ERRO]: ahhh!: Utf8Error { valid_up_to: 2, error_len: Some(1) }\n```\n\nWouldn't it be better if this was the alternative?\n\n```\n[ERRO]: ahhh!: error reading message: failed to convert input into string: expected utf-8 code point\n\u003e [01 05 68 65 ff 6c 6f]\n               ^^       \nadditional:\n  error offset: 4, input length: 7\nbacktrace:\n  1. `read all input`\n  2. `\u003ccontext\u003e` (expected message)\n  3. `\u003ccontext\u003e` (expected body)\n  4. `convert input into string` (expected utf-8 code point)\n```\n\n## Inspiration\n\nThis project was originally inspired by [untrusted](https://github.com/briansmith/untrusted).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favitex%2Frust-dangerous","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Favitex%2Frust-dangerous","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favitex%2Frust-dangerous/lists"}