refactor(kfn): Refactor KRandom implementations using declarative macro#31
Merged
zouguangxian merged 1 commit intoLayerZero-Labs:mainfrom Mar 8, 2026
Merged
Conversation
PR SummaryLow Risk Overview The generated impls now uniformly call Written by Cursor Bugbot for commit 82be757. This will update automatically on new commits. Configure here. |
Replace 12 nearly identical trait implementations (120+ lines) with a single declarative macro invocation, reducing code to ~25 lines. Benefits: - Eliminates code duplication (DRY principle) - Easier to maintain and extend - Consistent implementation across all integer types - Uses core::mem::size_of for all types (more robust than hardcoded sizes) The macro generates identical code for all primitive integer types: u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize No functional changes - all implementations behave exactly as before.
82be757 to
a2bcbaa
Compare
zouguangxian
approved these changes
Mar 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request refactors the implementation of the
KRandomtrait for integer types inrandom.rsto significantly reduce boilerplate and improve maintainability. Instead of writing separate implementations for each integer type, a macro is introduced to generate them automatically.Trait implementation refactoring:
impl_krandom!macro to implement theKRandomtrait for multiple integer types, replacing twelve separate manual implementations with a single macro invocation.u8,u16,u32,u64,u128,usize,i8,i16,i32,i64,i128, andisize.