refactor: extract shared truncate_str helper into renderers/utils.rs#183
Merged
Conversation
Move the byte-identical private truncate_str functions from vgpu_renderer and mig_renderer into a new pub(crate) src/ui/renderers/utils.rs module. Add comprehensive unit tests covering empty string, shorter/equal/longer than cap, max_chars=0, and multibyte UTF-8 (CJK and emoji) inputs. Closes #179
Member
Author
Implementation Review SummaryIntent
Findings AddressedNone — no CRITICAL/HIGH/MEDIUM/LOW findings were raised. Remaining ItemsNone. Verification
Notes
|
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.
Summary
truncate_strfunction existed as byte-identical copies in bothvgpu_renderer.rsandmig_renderer.rssrc/ui/renderers/utils.rsmodule (pub(crate)visibility)src/ui/renderers/mod.rsaspub(crate) mod utilsvgpu_renderer.rsandmig_renderer.rsto import and usecrate::ui::renderers::utils::truncate_strImplementation notes
src/ui/renderers/utils.rs(new dedicated file).mod.rsonly contained module declarations and re-exports, not shared helpers, so a separateutils.rsis the cleaner choice.chars().count()andchars().take(), not byte-based — no behavioral change.Tests added
The new
utils.rsmodule includes 8 unit tests covering:max_chars = 1(only ellipsis returned)max_chars = 0edge case (empty input stays empty; non-empty input yields"…")Test plan
cargo buildpassescargo testpasses (499 unit tests + 547 integration tests — all green)cargo clippy -- -D warningsproduces no warningscargo fmt) applied and committedCloses #179