pub struct StringRange {
pub start_offset: u32,
pub end_offset: u32,
}Expand description
Identifies a substring within a given text using character offsets.
Uses zero-based Unicode character offsets where start_offset is inclusive and end_offset is
exclusive.
Commonly used in autocomplete responses to indicate which portions of text matched the user’s input, allowing UI highlighting of relevant segments.
Note: Offsets are Unicode character positions, not byte positions, which is important for proper handling of multi-byte characters.
Fields§
§start_offset: u32Zero-based offset of the first Unicode character (inclusive).
The starting position of the substring within the parent text.
end_offset: u32Zero-based offset of the last Unicode character (exclusive).
The ending position of the substring, where the character at this position is not included in the range.
Implementations§
Source§impl StringRange
impl StringRange
Sourcepub fn start_offset(&self) -> &u32
pub fn start_offset(&self) -> &u32
Zero-based offset of the first Unicode character (inclusive).
The starting position of the substring within the parent text.
Sourcepub fn end_offset(&self) -> &u32
pub fn end_offset(&self) -> &u32
Zero-based offset of the last Unicode character (exclusive).
The ending position of the substring, where the character at this position is not included in the range.
Source§impl StringRange
impl StringRange
Sourcepub fn start_offset_mut(&mut self) -> &mut u32
pub fn start_offset_mut(&mut self) -> &mut u32
Zero-based offset of the first Unicode character (inclusive).
The starting position of the substring within the parent text.
Sourcepub fn end_offset_mut(&mut self) -> &mut u32
pub fn end_offset_mut(&mut self) -> &mut u32
Zero-based offset of the last Unicode character (exclusive).
The ending position of the substring, where the character at this position is not included in the range.
Source§impl StringRange
impl StringRange
Sourcepub fn set_start_offset(&mut self, val: u32) -> &mut Self
pub fn set_start_offset(&mut self, val: u32) -> &mut Self
Zero-based offset of the first Unicode character (inclusive).
The starting position of the substring within the parent text.
Sourcepub fn set_end_offset(&mut self, val: u32) -> &mut Self
pub fn set_end_offset(&mut self, val: u32) -> &mut Self
Zero-based offset of the last Unicode character (exclusive).
The ending position of the substring, where the character at this position is not included in the range.
Source§impl StringRange
impl StringRange
Sourcepub fn builder() -> StringRangeBuilder
pub fn builder() -> StringRangeBuilder
Create an instance of StringRange using the builder syntax
Source§impl StringRange
impl StringRange
Sourcepub const fn new(start_offset: u32, end_offset: u32) -> Self
pub const fn new(start_offset: u32, end_offset: u32) -> Self
Creates a new StringRange from start and end offsets.
Creates a range where start_offset is inclusive and end_offset is exclusive, matching
standard range semantics.
Use this when constructing ranges from API responses or when manually specifying text segments to highlight.
Sourcepub const fn start(self) -> u32
pub const fn start(self) -> u32
Returns the start offset (inclusive).
The zero-based Unicode character position where the range begins.
Sourcepub const fn end(self) -> u32
pub const fn end(self) -> u32
Returns the end offset (exclusive).
The zero-based Unicode character position where the range ends. The character at this position is not included in the range.
Sourcepub const fn len(self) -> u32
pub const fn len(self) -> u32
Returns the length of the range in characters.
Calculates the number of Unicode characters covered by this range.
Use this to determine how many characters to highlight or extract.
Trait Implementations§
Source§impl Clone for StringRange
impl Clone for StringRange
Source§fn clone(&self) -> StringRange
fn clone(&self) -> StringRange
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for StringRange
impl Debug for StringRange
Source§impl<'de> Deserialize<'de> for StringRange
impl<'de> Deserialize<'de> for StringRange
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for StringRange
impl Display for StringRange
Source§impl PartialEq for StringRange
impl PartialEq for StringRange
Source§impl Serialize for StringRange
impl Serialize for StringRange
Source§impl TryFrom<&StringRange> for Range<usize>
impl TryFrom<&StringRange> for Range<usize>
Source§fn try_from(string_range: &StringRange) -> Result<Self, Self::Error>
fn try_from(string_range: &StringRange) -> Result<Self, Self::Error>
Converts a borrowed &StringRange to a Rust Range<usize>.
Attempts to convert the StringRange offsets to usize for use with string slicing without
consuming the original.
§Errors
Returns an error if either offset is negative or too large to fit in a usize.
Source§type Error = TryFromIntError
type Error = TryFromIntError
Source§impl TryFrom<StringRange> for Range<usize>
impl TryFrom<StringRange> for Range<usize>
Source§fn try_from(string_range: StringRange) -> Result<Self, Self::Error>
fn try_from(string_range: StringRange) -> Result<Self, Self::Error>
Converts a StringRange to a Rust Range<usize>.
Attempts to convert the StringRange offsets to usize for use with string slicing.
§Errors
Returns an error if either offset is negative or too large to fit in a usize.
Source§type Error = TryFromIntError
type Error = TryFromIntError
impl Copy for StringRange
impl Eq for StringRange
impl StructuralPartialEq for StringRange
Auto Trait Implementations§
impl Freeze for StringRange
impl RefUnwindSafe for StringRange
impl Send for StringRange
impl Sync for StringRange
impl Unpin for StringRange
impl UnsafeUnpin for StringRange
impl UnwindSafe for StringRange
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.