⚡ Bolt: [DRY Refactor] Introduce define_native helper to reduce boilerplate - #409
⚡ Bolt: [DRY Refactor] Introduce define_native helper to reduce boilerplate#409logbie wants to merge 1 commit into
define_native helper to reduce boilerplate#409Conversation
Added a `define_native` helper method to the `Environment` struct to reduce the boilerplate associated with registering native functions. Updated all call sites in the standard library to use this new helper. Co-authored-by: logbie <1138960+logbie@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (11)
📝 WalkthroughWalkthroughThis PR introduces a new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip CodeRabbit can enforce grammar and style rules using `languagetool`.Configure the |
There was a problem hiding this comment.
Pull request overview
This PR reduces boilerplate and eliminates duplicated string literals when registering standard-library native functions by introducing an Environment::define_native helper and updating stdlib modules to use it.
Changes:
- Added
Environment::define_native(name, func)to wrapValue::NativeFunction(name, func)and calldefine. - Refactored stdlib registration code across multiple modules to use
env.define_native(...)instead ofenv.define(..., Value::NativeFunction(...)).
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/interpreter/environment.rs | Adds define_native helper for consistent native-function registration. |
| src/stdlib/core.rs | Uses define_native for core native registrations and aliases. |
| src/stdlib/crypto.rs | Refactors crypto native registrations to define_native. |
| src/stdlib/filesystem.rs | Refactors filesystem native registrations to define_native. |
| src/stdlib/json.rs | Refactors JSON native registrations to define_native. |
| src/stdlib/list.rs | Refactors list native registrations and aliases to define_native. |
| src/stdlib/math.rs | Refactors math native registrations to define_native. |
| src/stdlib/pattern.rs | Refactors pattern native registrations to define_native. |
| src/stdlib/random.rs | Refactors random native registrations to define_native. |
| src/stdlib/text.rs | Refactors text native registrations and aliases to define_native. |
| src/stdlib/time.rs | Refactors time native registrations to define_native. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Closing: bot-generated PR, cleaning up duplicates. |
Summary of Changes
src/stdlib/*.rs). The patternenv.define("name", Value::NativeFunction("name", func))was repeated over 100 times, violating the DRY principle and introducing a potential source of bugs if the string literal name inenv.definedid not match the string literal insideValue::NativeFunction.define_nativemethod on theEnvironmentstruct (src/interpreter/environment.rs) that accepts the name and function pointer, automatically constructing theValue::NativeFunctionwrapper. Refactored all standard library modules (math,core,list,crypto,json,time,text,random,filesystem,pattern) to useenv.define_native.Verification Checklist
cargo fmtexecuted and passed.cargo clippyreturned no warnings or errors.cargo testsuites passed (100% success rate).PR created automatically by Jules for task 2804966990401941479 started by @logbie
Summary by CodeRabbit