{"id":51514752,"url":"https://github.com/jamesgober/type-lib","last_synced_at":"2026-07-08T10:01:45.879Z","repository":{"id":359485163,"uuid":"1242968722","full_name":"jamesgober/type-lib","owner":"jamesgober","description":"Validation and type constraint library. Declare domain types with invariants enforced at construction (NonEmpty, BoundedInt, EmailAddress, etc.). Parse-don't-validate pattern as a first-class citizen. Zero-overhead wrappers with derive macros.","archived":false,"fork":false,"pushed_at":"2026-05-22T03:55:03.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-22T12:48:53.911Z","etag":null,"topics":["newtype","parse","reps","rust","types","validation"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jamesgober.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"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}},"created_at":"2026-05-18T23:48:06.000Z","updated_at":"2026-05-22T03:55:07.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/jamesgober/type-lib","commit_stats":null,"previous_names":["jamesgober/type-lib"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/jamesgober/type-lib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesgober%2Ftype-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesgober%2Ftype-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesgober%2Ftype-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesgober%2Ftype-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jamesgober","download_url":"https://codeload.github.com/jamesgober/type-lib/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesgober%2Ftype-lib/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35260671,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-08T02:00:06.796Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["newtype","parse","reps","rust","types","validation"],"created_at":"2026-07-08T10:01:44.614Z","updated_at":"2026-07-08T10:01:45.838Z","avatar_url":"https://github.com/jamesgober.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿\u003ch1 align=\"center\"\u003e\n    \u003cimg width=\"99\" alt=\"Rust logo\" src=\"https://raw.githubusercontent.com/jamesgober/rust-collection/72baabd71f00e14aa9184efcb16fa3deddda3a0a/assets/rust-logo.svg\"\u003e\n    \u003cbr\u003e\n    \u003cstrong\u003etype-lib\u003c/strong\u003e\n    \u003cbr\u003e\n    \u003csup\u003e\u003csub\u003eVALIDATED DOMAIN TYPES FOR RUST\u003c/sub\u003e\u003c/sup\u003e\n\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://crates.io/crates/type-lib\"\u003e\u003cimg alt=\"crates.io\" src=\"https://img.shields.io/crates/v/type-lib.svg\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://crates.io/crates/type-lib\"\u003e\u003cimg alt=\"downloads\" src=\"https://img.shields.io/crates/d/type-lib.svg\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://docs.rs/type-lib\"\u003e\u003cimg alt=\"docs.rs\" src=\"https://docs.rs/type-lib/badge.svg\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/rust-lang/rfcs/blob/master/text/2495-min-rust-version.md\" title=\"MSRV\"\u003e\u003cimg alt=\"MSRV\" src=\"https://img.shields.io/badge/MSRV-1.75%2B-blue\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/jamesgober/type-lib/actions/workflows/ci.yml\"\u003e\u003cimg alt=\"CI\" src=\"https://github.com/jamesgober/type-lib/actions/workflows/ci.yml/badge.svg\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003eParse-dont-validate as a first-class citizen. Domain types with invariants enforced at construction. Zero-overhead wrappers.\u003c/p\u003e\n\n\n## What it does\n\n`type-lib` makes invalid states unrepresentable. Instead of validating a value\nevery time it is used, you validate it **once** — at construction — and carry a\ntype that the compiler will only let exist in a valid state. Functions that take\nsuch a type are freed from defensive checks: the type system already did them.\n\nThe foundation is two pieces that compose:\n\n- [`Validator`](docs/API.md#validator) — a reusable, type-level validation rule.\n  It lives on a zero-sized marker type and is selected through the type system,\n  so it carries no state and no storage.\n- [`Refined`](docs/API.md#refined) — a `#[repr(transparent)]` wrapper holding a\n  value proven to satisfy a `Validator`. It has the exact size and layout of the\n  value it wraps, so the guarantee is free at runtime.\n\nA ready-made [`ValidationError`](docs/API.md#validationerror) covers rules that\nneed only a code and a message; rules that need structured failures define their\nown error type through `Validator::Error`.\n\n---\n\n## Features\n\n- **Parse, don't validate** — invariants are enforced at construction and proven\n  by the type thereafter; no re-checking at call sites.\n- **Zero-overhead wrappers** — `Refined\u003cT, V\u003e` is `#[repr(transparent)]` over `T`\n  and stores nothing extra. The validated type is the same size as the raw one.\n- **Built-in rules** — ready-made validators for length\n  ([`NonEmpty`](docs/API.md#length-rules), `MinLen`, `MaxLen`, `LenRange`), numbers\n  (`Positive`, `InRange`, …), and string content (`Ascii`, `Alphanumeric`,\n  `Trimmed`).\n- **Composition** — combine rules at the type level with\n  [`And`](docs/API.md#combinators), `Or`, and `Not`; the result is itself a rule.\n- **Derive macro** — `#[derive(Validated)]` (the `derive` feature) turns a newtype\n  into a named domain type with a checked constructor.\n- **Reusable, type-level rules** — write a `Validator` once and apply it to any\n  value type through the type system.\n- **Tamper-proof by construction** — `Refined` exposes no `\u0026mut` to its inner\n  value and no public field, so a validated value cannot be mutated into an\n  invalid one behind the type's back.\n- **Bring your own error** — use the bundled `ValidationError` or any custom\n  error type via the `Validator::Error` associated type.\n- **`no_std` friendly** — the core API and all borrowed-value rules work without\n  `std`; `alloc` adds owned-type (`String` / `Vec`) length rules and `std` adds\n  the [`std::error::Error`] impl.\n- **Cross-platform** — Linux, macOS, and Windows on stable and MSRV 1.75.\n\n---\n\n## Performance\n\nValidation is the only runtime cost; the wrapper adds none. Local Criterion means\n(Windows x86_64, Rust stable, `cargo bench`):\n\n- `Refined::new` with `Ascii` on a short `\u0026str`: **~0.9 ns**\n- `Refined::new` with `LenRange\u003c3, 16\u003e` on a `\u0026str`: **~2.2 ns**\n- `Refined::new` with `InRange\u003c0, 100\u003e` on an `i32`: **~2.6 ns**\n- `get` / `Deref` accessors: **sub-nanosecond** (compile down to a field read)\n\n---\n\n## API Overview\n\nFor the complete reference with examples, see [docs/API.md](docs/API.md).\n\n- [`Validator`](docs/API.md#validator) — reusable, type-level validation rule\n- [`Refined`](docs/API.md#refined) — zero-cost wrapper around a validated value\n- [`ValidationError`](docs/API.md#validationerror) — ready-made `no_std` error\n- [Built-in rules](docs/API.md#built-in-rules) — length, numeric, and string rules\n- [Combinators](docs/API.md#combinators) — `And`, `Or`, `Not`\n- [`Validated`](docs/API.md#validated-derive) — `#[derive]` for validated newtypes (`derive` feature)\n- [`prelude`](docs/API.md#prelude) — convenient re-exports\n- [`VERSION`](docs/API.md#version) — compile-time crate version\n\nRunnable demos live in [`examples/`](examples): `quick_start`, `built_in_rules`,\n`composing_rules`, `custom_rule`, and `derive_newtype`\n(e.g. `cargo run --example quick_start`).\n\n---\n\n## Installation\n\n```toml\n[dependencies]\ntype-lib = \"1.0.0\"\n\n# with the derive macro\ntype-lib = { version = \"1.0.0\", features = [\"derive\"] }\n\n# no_std build (core API + borrowed-value rules)\ntype-lib = { version = \"1.0.0\", default-features = false }\n\n# no_std + owned-type rules (String / Vec)\ntype-lib = { version = \"1.0.0\", default-features = false, features = [\"alloc\"] }\n```\n\nMSRV: Rust 1.75.\n\n## Quick start\n\n```rust\nuse type_lib::combinator::And;\nuse type_lib::rules::{LenRange, Trimmed};\nuse type_lib::Refined;\n\n// A username: 3–16 characters with no surrounding whitespace.\n// Built once, the type guarantees the invariant everywhere it is used.\ntype Username = Refined\u003cString, And\u003cTrimmed, LenRange\u003c3, 16\u003e\u003e\u003e;\n\nfn main() {\n    let user = Username::new(\"alice\".to_owned());\n    assert!(user.is_ok());\n\n    assert!(Username::new(\"ab\".to_owned()).is_err());        // too short\n    assert!(Username::new(\"  alice  \".to_owned()).is_err()); // whitespace\n}\n```\n\nPrefer a distinct named type with its own constructor? Enable the `derive`\nfeature and annotate a newtype:\n\n```rust\nuse type_lib::combinator::And;\nuse type_lib::rules::{LenRange, Trimmed};\nuse type_lib::Validated;\n\n#[derive(Validated)]\n#[valid(And\u003cTrimmed, LenRange\u003c3, 16\u003e\u003e)]\npub struct Username(String);\n\nlet user = Username::new(\"alice\".to_owned());\nassert!(user.is_ok());\n```\n\nNeed a rule the built-ins don't cover? Implement [`Validator`](docs/API.md#validator)\non a marker type — see the [`custom_rule`](examples/custom_rule.rs) example.\n\nFor the exhaustive API reference, see [docs/API.md](docs/API.md).\n\n---\n\n## Standards\n\n- **REPS** governs every decision. See [REPS.md](REPS.md).\n- **MSRV:** Rust 1.75.\n- **Edition:** 2021.\n- **Cross-platform:** Linux, macOS, Windows.\n\n---\n\n## License\n\nDual-licensed under either of:\n\n- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE))\n- MIT License ([LICENSE-MIT](LICENSE-MIT))\n\nat your option.\n\n\n\n\u003c!-- FOOT COPYRIGHT\n################################################# --\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003ch2\u003e\u003c/h2\u003e\n  \u003csup\u003eCOPYRIGHT \u003csmall\u003e\u0026copy;\u003c/small\u003e 2026 \u003cstrong\u003eJAMES GOBER.\u003c/strong\u003e\u003c/sup\u003e\n\u003c/div\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesgober%2Ftype-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamesgober%2Ftype-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesgober%2Ftype-lib/lists"}