-
-
Notifications
You must be signed in to change notification settings - Fork 81
feat: improve custom function support to accept Dynamic types instead of only ImmutableString #395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
…ly ImmutableString Co-authored-by: hsluoyz <[email protected]>
Co-authored-by: hsluoyz <[email protected]>
Benchmark for 53ddd1dClick to view benchmark
|
Co-authored-by: hsluoyz <[email protected]>
Benchmark for 934ab02Click to view benchmark
|
Benchmark for 934ab02Click to view benchmark
|
Benchmark for 934ab02Click to view benchmark
|
Benchmark for 934ab02Click to view benchmark
|
|
@copilot the CI error in this PR needs to be fixed: https://github.com/casbin/casbin-rs/actions/runs/18440223770/job/52539595437?pr=395 |
Co-authored-by: hsluoyz <[email protected]>
Fixed the formatting issues. The CI was failing due to |
Benchmark for 934ab02Click to view benchmark
|
Benchmark for 934ab02Click to view benchmark
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR improves custom function support in Casbin-RS by replacing ImmutableString parameters with Rhai's Dynamic type, enabling custom functions to accept flexible argument types including integers, booleans, floats, arrays, and maps beyond just strings.
- Updated
OperatorFunctionenum to useDynamicinstead ofImmutableStringfor all argument variants - Added
dynamic_to_strhelper function for easy string conversion from Dynamic values - Created comprehensive test coverage and documentation for the new Dynamic-based custom functions
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/model/function_map.rs | Core enum update from ImmutableString to Dynamic, updated built-in functions, added helper function |
| src/enforcer.rs | Updated existing test and added comprehensive test for Dynamic custom functions |
| CUSTOM_FUNCTIONS.md | New comprehensive documentation with examples and migration guide |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #395 +/- ##
=========================================
- Coverage 65.54% 0 -65.55%
=========================================
Files 25 0 -25
Lines 1956 0 -1956
=========================================
- Hits 1282 0 -1282
+ Misses 674 0 -674 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
# [2.15.0](v2.14.0...v2.15.0) (2025-10-24) ### Features * improve custom function support to accept Dynamic types instead of only ImmutableString ([#395](#395)) ([52bc1ad](52bc1ad))
|
🎉 This PR is included in version 2.15.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Fix: #335
Summary
This PR improves custom function support in Casbin-RS to accept flexible argument types beyond just strings, addressing the limitation described in the issue.
Changes Made
Core Changes
OperatorFunctionenum to acceptDynamicinstead ofImmutableStringfor all argument positions (Arg0-Arg6)Dynamicdynamic_to_strhelper function for easy string conversionTesting
test_custom_function_with_dynamic_typesdemonstrating:Documentation
OperatorFunctionenum with examplesdynamic_to_strhelper functionCUSTOM_FUNCTIONS.mdguide with:Benefits
Custom functions can now work with:
Backward Compatibility
✅ Fully backward compatible - all existing code continues to work without changes. Strings are automatically converted to
Dynamicby Rhai.Example Usage
Files Changed
src/model/function_map.rs- Core enum and built-in function updatessrc/enforcer.rs- Test updates and examplesCUSTOM_FUNCTIONS.md- Comprehensive usage guide (new file)Testing Results
This implementation brings Casbin-RS in line with other Casbin implementations (Go, Java, Node.js) that support flexible custom function arguments.
Original prompt
Fixes #335
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.