feat: add ParseAs and NewSchema generics
Test / test (push) Successful in 1m38s

Assisted-by: GLM 5.3 Flash
This commit is contained in:
2026-09-22 00:36:10 +02:00
parent b02471c09a
commit 71bd82a7a5
4 changed files with 73 additions and 0 deletions
+17
View File
@@ -80,6 +80,23 @@ The one-shot form of a configured `Decoder`: the same options as
The zero value takes the defaults: unknown keys ignored, numbers evaluated
as `int64` and `float64`, no size limit and the 10000-level nesting default.
### `func ParseAs[T any](data []byte) (T, error)`
The generic shorthand for `Unmarshal` with a destination variable:
```go
cfg, err := interpres.ParseAs[Config](data)
```
The zero `T` comes back with the error.
### `func NewSchema[T any]()`
Precompiles the codec for `T`: the struct schema both directions walk and the
interface flags the decoder and encoder resolve through are built once and
cached, so the first document pays the cost instead of the hot path. A `T`
that is not a struct warms nothing.
## Documents
`Parse` returns a `Document`: the value tree together with what a map cannot