Skip to content

Add try_newtype_datatype! for fallible domain conversions#21

Merged
emilk merged 3 commits into
mainfrom
emilk/try-newtype-datatype
Jul 3, 2026
Merged

Add try_newtype_datatype! for fallible domain conversions#21
emilk merged 3 commits into
mainfrom
emilk/try-newtype-datatype

Conversation

@emilk

@emilk emilk commented Jul 3, 2026

Copy link
Copy Markdown
Member

Related

What

newtype_datatype! handles infallible Owned -> Newtype conversions. This adds try_newtype_datatype!, its fallible sibling, for newtypes that impl TryFrom<Owned> — the build direction (From<Newtype> for Owned) stays infallible. The TryFrom::Error must be std::error::Error + Send + Sync + 'static.

Consistent with Column's "validate once at construction, then read infallibly" contract, every value is checked eagerly in downcast (Column::try_new and the derive's record-batch parsing). A rejected value stops there, boxing the TryFrom error into the new ColumnError::Conversion, surfaced as the new ErrorKind::Conversion { column, source } once the column name is known. After construction, element access stays infallible.

Same noref / primitive arm options as newtype_datatype!.

Testing

  • New fallible_newtype_columns integration test (Even/NotEven newtype): build via infallible From, borrowed + owned reads, primitive bulk as_slice, eager rejection at try_newColumnError::Conversion, Option<Even> null-skipping, and ErrorKind::Conversion via from_record_batch_and_name.
  • Macro doctest.
  • cargo clippy --all-features --all-targets clean; cargo test --all-features green.

Compatibility

Additive: new macro plus new non-exhaustive-style variants on ColumnError and ErrorKind. Both enums already carried multiple variants; downstream exhaustive matches on them would need the new arm.

🤖 Generated with Claude Code

`newtype_datatype!` handles infallible `Owned -> Newtype` conversions.
`try_newtype_datatype!` is its fallible sibling, for newtypes that
`impl TryFrom<Owned>` (the build direction, `From<Newtype> for Owned`,
stays infallible).

Consistent with `Column`'s "validate once at construction, then read
infallibly" contract, every value is checked eagerly in `downcast`
(`Column::try_new` and derive parsing). A rejected value stops there,
boxing the `TryFrom` error into the new `ColumnError::Conversion`,
surfaced as the new `ErrorKind::Conversion { column, source }` once the
column name is known.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@emilk emilk marked this pull request as ready for review July 3, 2026 21:17
emilk and others added 2 commits July 3, 2026 14:18
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
These are all TryFrom a primitive quiver already supports (infallible
back), so they slot straight into try_newtype_datatype!:
  - NonZeroI8..I64, NonZeroU8..U64, stored as their plain integer
  - char, stored as UInt32 (surrogates/out-of-range rejected)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@emilk emilk merged commit 4610604 into main Jul 3, 2026
6 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.

1 participant