Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions attributed_text/src/attributed_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ impl<T: Debug + TextStorage, Attr: Debug> AttributedText<T, Attr> {
///
/// Attributes are yielded in the order they were applied. This doesn't handle conflicting
/// attributes, it just reports everything.
///
/// This performs a full scan of all attributes on each call (`O(n)` in applied span count).
pub fn attributes_at(&self, index: usize) -> impl Iterator<Item = (&Range<usize>, &Attr)> {
self.attributes.iter().filter_map(move |(attr_span, attr)| {
if attr_span.contains(&index) {
Expand All @@ -103,6 +105,13 @@ impl<T: Debug + TextStorage, Attr: Debug> AttributedText<T, Attr> {
///
/// Attributes are yielded in the order they were applied. This doesn't handle conflicting
/// attributes, it just reports everything.
///
/// This performs a full scan of all attributes on each call (`O(n)` in applied span count).
///
/// Use this for one-off overlap queries. For many queries over the same text, prefer
/// segment-based iteration with [`AttributeSegmentsWorkspace`](crate::AttributeSegmentsWorkspace):
/// segment once, then intersect your query ranges with yielded segments (which also provides
/// the exact covered subranges).
pub fn attributes_for_range(
&self,
range: Range<usize>,
Expand Down