Repository navigation
Add a NullOrUndefined<T> to Rust JSG as a clearer alternative to Option<Nullable<T>> - #8080
Conversation
|
✅ Approved — The changes since the last review (the macro's handling of optional fields and the new unit tests) are correct, and nothing in the pull request raises a correctness, security, performance or documentation concern. The decision is advisory: this comment never approves, blocks or requests changes on the pull request. ✅ All checks passed🔒 Security: ✅ LGTMThe change adds a plain Rust enum, its conversions and its macro handling. It adds no trust boundary and does not touch secrets, injection or authorization paths. 📖 AGENTS.md: ✅ LGTMThe 📋 Code Quality: ✅ LGTM
⚡ Performance: ✅ LGTMThe change adds a plain enum, its conversions and its macro handling. None of it adds work per request that could slow things down. 📝 Documentation: ✅ LGTMThe README, the jsg-macros README and the review checklist describe the new type accurately. Reviewed commit: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8080 +/- ##
==========================================
- Coverage 69.38% 69.24% -0.14%
==========================================
Files 696 698 +2
Lines 181869 182494 +625
Branches 29215 29223 +8
==========================================
+ Hits 126188 126376 +188
- Misses 38612 39046 +434
- Partials 17069 17072 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Represent optional nullable values as Some(T), Null, or Undefined without nesting Option and Nullable. Support JavaScript conversion, omitted method arguments, struct-field omission, and GC tracing. Add state predicates, borrowing and mapping helpers, and conversions preserving all three states. Integrate the type with Lenient, including its to_parts() return value, while retaining Option<Nullable<T>> conversions. Recommend NullOrUndefined<T> throughout the API docs, macro reference, review checklist, and agent guidance. Use consuming, fallible ToJS conversions for struct fields and preserve upstream field tracing, Dict support, numeric conversions, and Web IDL function lengths. Cover non-Clone payload conversion errors and optional-argument lengths under both compatibility settings. Validation: Rust formatting and Clippy pass for all Rust rule targets under src/rust, including unit and integration tests. The full Rust suite passes all 117 applicable test targets; two sanitizer targets are skipped.
a281e31 to
a56bdff
Compare
The main motivation is explicitness, particularly when handling the value, followed by reducing the syntactic noise for a common case. This came up in discussions with @mikea
Consider
Option<Nullable<T>>:vs
NullOrUndefined<T>:The semantics and meaning of
NullOrUndefinedare immediately clear, whereas the meaning ofNonebeingundefinedis non-obvious.This PR adds the type and makes it the recommended way to represent
T | null | undefinedin Rust JSG.Option<Nullable<T>>remains but is not advertised as prominently in the docs.Feel free to bikeshed the naming, names are hard.