Skip to content

feat: add typed decode results - #10

Merged
cmilesio merged 2 commits into
mainfrom
feat/go-1.27-generic-methods
Aug 23, 2026
Merged

feat: add typed decode results#10
cmilesio merged 2 commits into
mainfrom
feat/go-1.27-generic-methods

Conversation

@cmilesio

@cmilesio cmilesio commented Aug 23, 2026

Copy link
Copy Markdown
Member

What

Add DecodeChain.As[T], which runs the configured command and returns a decoded value directly. It uses the same decoder, output-source selection, trimming, execution, and error wrapping as Into; Into and DecodeWith remain unchanged.

Raise the root, docs, and examples modules to Go 1.27, add minimum-version and stable CI coverage, regenerate the API docs, and retain 100% statement coverage across success and failure paths. Older toolchains can remain on the v1.1 line.

Before and after

Decoded command results no longer need a temporary variable and mutable pointer:

DecodeChain.As

Before:

var result Result
err := execx.Command("tool", "inspect").
	DecodeJSON().FromStdout().Trim().Into(&result)

After:

result, err := execx.Command("tool", "inspect").
	DecodeJSON().FromStdout().Trim().As[Result]()

The chain now describes the whole operation and produces its typed result in one expression, while Into remains available when callers intentionally want to populate an existing value.

Why

The pointer-only result shape existed because earlier Go versions could not add a result type to a method. Go 1.27 lets the decode chain own that type, making the common case concise without changing the decoder interface or error contract.

Performance

End-to-end benchmarks include subprocess startup and JSON decoding. Into and As both remain at 88,787 B and 163 allocations, and both run in the same roughly 268–283 microsecond range on linux/arm64 with one P.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@cmilesio
cmilesio merged commit b7f09b9 into main Aug 23, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants