attributed_text: add reusable sweep segmentation for unchecked spans#630
Merged
waywardmonkeys merged 1 commit intoMay 26, 2026
Merged
Conversation
1d2566e to
bc8dd7e
Compare
tomcur
approved these changes
May 26, 2026
Member
There was a problem hiding this comment.
This looks good.
My main concern is somewhat orthogonal and take-it-or-leave-it: the API uses the word "validated" for parts where the data is assumed to be correct, whereas often in Rust that relation is flipped, using try_, checked_, or some other term for APIs that validate (otherwise assuming the data passed in is correct).
Contributor
Author
|
This assumes the caller validated it. More of an unchecked. |
This adds a reusable sweep-line path to `attributed_text` so callers can segment a trusted span slice without rebuilding a temporary `AttributedText`. The main public addition is `AttributeSegmentsWorkspace::for_each_span_segment_unchecked`, which reports each resolved segment plus the active span indices in application order. The name is intentionally explicit: the method does not validate in release builds that the `TextRange` values belong to the text length supplied by the caller. This also adds `AttributedText::from_attributes_unchecked` for constructing attributed text from an existing attribute vector while preserving application order. Callers should prefer `apply_attribute_bytes` or `TextRange::new` unless the spans have already been checked against the exact text storage. This is needed by the styled-text builder path, which already has patch ranges in `TextRange` form and wants to resolve overlaps without allocating an intermediate attributed-text value. The API is callback-based so the sweep result can be exposed without committing to extra iterator structs.
bc8dd7e to
6503ed2
Compare
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.
The main public addition is AttributeSegmentsWorkspace::for_each_span_segment_uncheattributed_text: add reusable sweep segmentation for unchecked spans
This adds a reusable sweep-line path to
attributed_textso callers can segment a trusted span slice without rebuilding a temporaryAttributedText.The main public addition is
AttributeSegmentsWorkspace::for_each_span_segment_unchecked, which reports each resolved segment plus the active span indices in application order. The name is intentionally explicit: the method does not validate in release builds that theTextRangevalues belong to the text length supplied by the caller.This also adds
AttributedText::from_attributes_uncheckedfor constructing attributed text from an existing attribute vector while preserving application order. Callers should preferapply_attribute_bytesorTextRange::newunless the spans have already been checked against the exact text storage.This is needed by the styled-text builder path, which already has patch ranges in
TextRangeform and wants to resolve overlaps without allocating an intermediate attributed-text value. The API is callback-based so the sweep result can be exposed without committing to extra iterator structs.