{"id":49915523,"url":"https://github.com/mathematic-inc/protovalidate-buffa","last_synced_at":"2026-05-25T04:07:22.598Z","repository":{"id":354389390,"uuid":"1216974785","full_name":"mathematic-inc/protovalidate-buffa","owner":"mathematic-inc","description":"Static-codegen protovalidate for the buffa Rust protobuf runtime","archived":false,"fork":false,"pushed_at":"2026-05-14T23:27:24.000Z","size":457,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-15T01:30:42.639Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":false,"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/mathematic-inc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE-APACHE","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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"mathematic-inc"}},"created_at":"2026-04-21T12:22:03.000Z","updated_at":"2026-05-14T23:27:20.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/mathematic-inc/protovalidate-buffa","commit_stats":null,"previous_names":["mathematic-inc/protovalidate-buffa"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/mathematic-inc/protovalidate-buffa","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathematic-inc%2Fprotovalidate-buffa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathematic-inc%2Fprotovalidate-buffa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathematic-inc%2Fprotovalidate-buffa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathematic-inc%2Fprotovalidate-buffa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mathematic-inc","download_url":"https://codeload.github.com/mathematic-inc/protovalidate-buffa/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathematic-inc%2Fprotovalidate-buffa/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33109461,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-16T04:41:52.686Z","status":"ssl_error","status_checked_at":"2026-05-16T04:41:52.009Z","response_time":115,"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":[],"created_at":"2026-05-16T16:01:05.643Z","updated_at":"2026-05-25T04:07:22.590Z","avatar_url":"https://github.com/mathematic-inc.png","language":"Rust","funding_links":["https://github.com/sponsors/mathematic-inc"],"categories":[],"sub_categories":[],"readme":"# protovalidate-buffa\n\nStatic-codegen [protovalidate] for the [buffa] Rust protobuf runtime.\n\nAnnotate your `.proto` messages with `(buf.validate.*)` rules; a codegen plugin emits pure-Rust `impl Validate` blocks per message. Handlers call `req.validate()?` at entry (or use the `#[connect_impl]` macro to do it automatically on every handler in a service impl).\n\nFor what the rules *mean*, the full rule catalogue, CEL semantics, and design docs, read the upstream project — this crate intentionally does not duplicate that material:\n\n- **Docs:** \u003chttps://buf.build/docs/protovalidate/\u003e\n- **Rule catalogue:** \u003chttps://buf.build/docs/protovalidate/schemas/standard-rules/\u003e\n- **Custom / predefined rules:** \u003chttps://buf.build/docs/protovalidate/schemas/custom-rules/\u003e\n- **Source of truth (`validate.proto`):** \u003chttps://github.com/bufbuild/protovalidate/blob/main/proto/protovalidate/buf/validate/validate.proto\u003e\n\n[protovalidate]: https://github.com/bufbuild/protovalidate\n[buffa]: https://github.com/anthropics/buffa\n\n## Status\n\n**Conformance: 2872 / 2872 (100%)** against the upstream [`protovalidate-conformance`](https://github.com/bufbuild/protovalidate/tree/main/tools/protovalidate-conformance) harness, covering proto2, proto3, and editions 2023.\n\n## Why a different crate?\n\nExisting Rust implementations of protovalidate (`prost-protovalidate`, `protocheck`, `protify`) all target [prost]. buffa has a different runtime model — zero-copy views, static types, no dynamic-message reflection — so prost-based validators are incompatible. This repo fills that gap.\n\nCompared to reflection-based implementations, the codegen approach has two characteristics:\n\n- **No runtime descriptor lookup.** Every `validate()` is a direct struct field walk that LLVM can inline.\n- **Schema-aware compile errors.** Rule / field type mismatches, malformed `message.oneof` specs, and CEL expressions that reference non-existent fields are surfaced at codegen time rather than at first-call.\n\n[prost]: https://github.com/tokio-rs/prost\n\n## Crates\n\n| Crate | Purpose |\n|-------|---------|\n| [`protovalidate-buffa`](crates/protovalidate-buffa/) | Runtime library: `Validate` trait, structured `ValidationError` (with typed `compile_error` / `runtime_error` slots), `Violation` / `FieldPath`, rule helpers, `CelScalar` widening trait + Duration/Timestamp helpers, Connect error adapter. CEL rules are transpiled to native Rust at codegen time, so the runtime carries no interpreter. |\n| [`protovalidate-buffa-macros`](crates/protovalidate-buffa-macros/) | `#[connect_impl]` attribute macro — inserts `req.validate()?` at the top of every handler in a service `impl` block. Re-exported from the runtime crate. |\n| [`protoc-gen-protovalidate-buffa`](crates/protoc-gen-protovalidate-buffa/) | Codegen plugin. Reads `(buf.validate.*)` extensions off descriptors via buffa's `ExtensionSet`, emits `impl Validate for Foo` blocks. Wire into `buf.gen.yaml`. |\n| [`protovalidate-buffa-protos`](crates/protovalidate-buffa-protos/) | Compiled Rust for `buf/validate/validate.proto` (vendored under `proto/`). Consumed by the codegen plugin. |\n\n`protovalidate-buffa-conformance` also lives in this workspace but is private (`publish = false`) — see [its README](crates/protovalidate-buffa-conformance/README.md) for the conformance test-run flow.\n\n## Supported rules\n\nEvery rule family in the upstream [standard-rules catalogue](https://buf.build/docs/protovalidate/schemas/standard-rules/) plus [predefined rules](https://buf.build/docs/protovalidate/schemas/custom-rules/#predefined-rules) is implemented — that's what the 2872 / 2872 conformance number above is measuring. See the upstream docs for semantics; this repo doesn't maintain a parallel list.\n\n## Quick start\n\nFor the proto-annotation side (which rules exist, how to combine them, CEL syntax), follow the upstream [protovalidate quick start](https://buf.build/docs/protovalidate/quickstart/). The Rust-specific bits are:\n\n```bash\n# Install the plugin\ncargo install --git https://github.com/mathematic-inc/protovalidate-buffa protoc-gen-protovalidate-buffa\n```\n\nAdd to your `buf.gen.yaml`:\n\n```yaml\n- local: protoc-gen-protovalidate-buffa\n  out: gen/protovalidate\n  strategy: all\n```\n\nAnnotate a proto (see upstream for the full rule vocabulary):\n\n```protobuf\nsyntax = \"proto3\";\nimport \"buf/validate/validate.proto\";\n\nmessage CreateUserRequest {\n  string email = 1 [(buf.validate.field).string = { min_len: 5, max_len: 254, email: true }];\n  int32 age = 3 [(buf.validate.field).int32 = { gte: 13, lte: 150 }];\n}\n```\n\nUse in a Connect handler:\n\n```rust\nuse protovalidate_buffa::Validate;\n\n#[protovalidate_buffa::connect_impl]\nimpl UserService for UserServiceImpl {\n    async fn create_user(\n        \u0026self,\n        ctx: Context,\n        request: OwnedView\u003cpb::CreateUserRequestView\u003c'static\u003e\u003e,\n    ) -\u003e Result\u003c(pb::CreateUserResponse, Context), ConnectError\u003e {\n        // #[connect_impl] inserts req.validate()? here automatically.\n        // Body only sees already-validated requests.\n    }\n}\n```\n\n## Error model\n\n`Validate::validate` returns `Result\u003c(), ValidationError\u003e`:\n\n```rust\npub struct ValidationError {\n    pub violations: Vec\u003cViolation\u003e,\n    pub compile_error: Option\u003cString\u003e,  // schema mismatch detected at codegen time\n    pub runtime_error: Option\u003cString\u003e,  // rule precondition failed (e.g. non-UTF-8 bytes under `pattern`)\n}\n```\n\nMatch on the typed fields rather than stringly-typed rule-id prefixes. `Violation` / `FieldPath` mirror the [upstream proto shape](https://github.com/bufbuild/protovalidate/blob/main/proto/protovalidate/buf/validate/validate.proto) — see those message definitions for field semantics. The `connect` feature provides `ValidationError::into_connect_error` mapping to `InvalidArgument`.\n\n## Conformance testing\n\nSee [`crates/protovalidate-buffa-conformance/README.md`](crates/protovalidate-buffa-conformance/README.md) for how to build the dispatch binary and drive the upstream harness locally. CI runs `cargo clippy --workspace --all-targets -- -D warnings` and `cargo test --workspace` on every push; conformance is currently a local-only / pre-release check.\n\n## License\n\nDual-licensed under Apache-2.0 or MIT at your option.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathematic-inc%2Fprotovalidate-buffa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmathematic-inc%2Fprotovalidate-buffa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathematic-inc%2Fprotovalidate-buffa/lists"}