# type-lib v0.6.0 — Derive
**Named validated newtypes, generated.** v0.6.0 adds `#[derive(Validated)]`: apply
it to a one-field tuple struct, point it at a [`Validator`] with `#[valid(...)]`,
and get a distinct domain type with a checked constructor and a private inner
field. It is delivered by a new companion proc-macro crate, `type-lib-derive`,
re-exported behind the `derive` feature. Purely additive — no breaking changes.
## What is type-lib?
A validation and type-constraint library for Rust. You declare domain types whose
invariants are enforced at construction and proven by the type system thereafter,
so code that receives a validated value never re-checks it. Wrappers are
zero-overhead, the core is `no_std`-friendly, and rules are reusable and
composable.
## What's new in 0.6.0
### `#[derive(Validated)]`
A `type X = Refined<T, V>` alias works, but it is an alias — not a distinct type.
The derive produces a real, named newtype with its own constructor and trait
impls, while reusing the exact same rules and combinators:
```rust
use type_lib::combinator::And;
use type_lib::rules::{LenRange, Trimmed};
use type_lib::Validated;
#[derive(Validated, Debug, Clone, PartialEq)]
#[valid(And<Trimmed, LenRange<3, 16>>)]
pub struct Username(String);
let user = Username::new("alice".to_owned()).expect("valid");
assert_eq!(user.get(), "alice");
assert!(Username::new(" alice ".to_owned()).is_err());
```
The `#[valid(...)]` attribute takes any type implementing [`Validator`] for the
field type — a [built-in rule], a [combinator], or your own with a structured
error. The derive generates:
- `fn new(value: T) -> Result<Self, <V as Validator<T>>::Error>`
- `fn get(&self) -> &T`, `fn into_inner(self) -> T`
- `Deref<Target = T>` and `AsRef<T>`
The inner field stays private, so the only way to build the type from outside its
module is through `new`. Add ordinary derives (`Debug`, `Clone`, `PartialEq`, …)
alongside `Validated` as usual. Misuse — a non-tuple struct, more than one field,
generics, or a missing/duplicated `#[valid(...)]` — produces a clear compile
error.
### Workspace + `type-lib-derive`
The derive lives in a new companion crate, `type-lib-derive` (a `proc-macro`
crate built on `syn`/`quote`), and the repository is now a Cargo workspace. You
do not depend on it directly — enable the `derive` feature on `type-lib`:
```toml
type-lib = { version = "0.6.0", features = ["derive"] }
```
The `derive` feature is off by default, so projects that do not use the macro pay
nothing for `syn`/`quote` in their build.
## Breaking changes
**None.** The `Validator` / `Refined` / `ValidationError` / rules / combinators
surface is unchanged. `#[derive(Validated)]` is new and opt-in behind the `derive`
feature.
## Verification
Run on Windows x86_64 (Rust stable 1.95 and MSRV 1.75.0) and on Linux (WSL2
Ubuntu); identical commands pass via the CI matrix (Linux/macOS/Windows ×
{stable, 1.75.0}):
```bash
cargo fmt --all -- --check
cargo clippy --workspace --all-targets --all-features -- -D warnings
cargo clippy --all-targets --no-default-features -- -D warnings
cargo test --workspace --all-features
cargo test --no-default-features
RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --all-features
```
All green. Counts at this tag:
- `--all-features`: 26 unit + 4 derive + 6 other integration + 8 property + 38 doctests.
- `--no-default-features`: 26 unit + 6 integration + 8 property + 37 doctests
(the derive test and doctest are gated off).
The published `type-lib` crate has no runtime dependencies by default; the
`derive` feature adds `syn` / `quote` / `proc-macro2` at build time. The committed
`Cargo.lock` keeps the dev-dependency tree on the MSRV (Rust 1.75).
## What's next
- **v0.9.0 — Hardening + audit.** Feature freeze, the pre-1.0 audit (API review,
error-path coverage, docs, benchmarks), and resolution of findings before the
1.0 stabilization.
## Installation
```toml
[dependencies]
type-lib = "0.6.0"
# with the derive macro
type-lib = { version = "0.6.0", features = ["derive"] }
# no_std (core API + borrowed-value rules)
type-lib = { version = "0.6.0", default-features = false }
```
MSRV: Rust 1.75.
## Documentation
- [README](https://github.com/jamesgober/type-lib/blob/main/README.md)
- [API Reference](https://github.com/jamesgober/type-lib/blob/main/docs/API.md)
- [CHANGELOG](https://github.com/jamesgober/type-lib/blob/main/CHANGELOG.md)
---
**Full diff:** [`v0.5.0...v0.6.0`](https://github.com/jamesgober/type-lib/compare/v0.5.0...v0.6.0).
**Changelog:** [`CHANGELOG.md`](https://github.com/jamesgober/type-lib/blob/main/CHANGELOG.md#060---2026-05-27).