pub struct TextSize { /* private fields */ }
Expand description
A measure of text length. Also, equivalently, an index into text.
This is a UTF-8 bytes offset stored as u32
, but
most clients should treat it as an opaque measure.
For cases that need to escape TextSize
and return to working directly
with primitive integers, TextSize
can be converted losslessly to/from
u32
via From
conversions as well as losslessly be converted Into
usize
. The usize -> TextSize
direction can be done via TryFrom
.
These escape hatches are primarily required for unit testing and when converting from UTF-8 size to another coordinate space, such as UTF-16.
Implementations
sourceimpl TextSize
impl TextSize
sourcepub fn of<T>(text: T) -> TextSizewhere
T: TextLen,
pub fn of<T>(text: T) -> TextSizewhere
T: TextLen,
The text size of some primitive text-like object.
Accepts char
, &str
, and &String
.
Examples
let char_size = TextSize::of('🦀');
assert_eq!(char_size, TextSize::from(4));
let str_size = TextSize::of("rust-analyzer");
assert_eq!(str_size, TextSize::from(13));
sourceimpl TextSize
impl TextSize
Methods to act like a primitive integer type, where reasonably applicable.
sourcepub fn checked_add(self, rhs: TextSize) -> Option<TextSize>
pub fn checked_add(self, rhs: TextSize) -> Option<TextSize>
Checked addition. Returns None
if overflow occurred.
sourcepub fn checked_sub(self, rhs: TextSize) -> Option<TextSize>
pub fn checked_sub(self, rhs: TextSize) -> Option<TextSize>
Checked subtraction. Returns None
if overflow occurred.
Trait Implementations
sourceimpl<A> AddAssign<A> for TextSizewhere
TextSize: Add<A>,
<TextSize as Add<A>>::Output == TextSize,
impl<A> AddAssign<A> for TextSizewhere
TextSize: Add<A>,
<TextSize as Add<A>>::Output == TextSize,
sourcefn add_assign(&mut self, rhs: A)
fn add_assign(&mut self, rhs: A)
Performs the +=
operation. Read more
sourceimpl From<LexerPosition> for TextSize
impl From<LexerPosition> for TextSize
sourcefn from(value: LexerPosition) -> Self
fn from(value: LexerPosition) -> Self
Converts to this type from the input type.
sourceimpl Ord for TextSize
impl Ord for TextSize
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl PartialEq<TextSize> for TextSize
impl PartialEq<TextSize> for TextSize
sourceimpl PartialOrd<TextSize> for TextSize
impl PartialOrd<TextSize> for TextSize
sourcefn partial_cmp(&self, other: &TextSize) -> Option<Ordering>
fn partial_cmp(&self, other: &TextSize) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl RangeBounds<TextSize> for TextRange
impl RangeBounds<TextSize> for TextRange
sourcefn start_bound(&self) -> Bound<&TextSize>
fn start_bound(&self) -> Bound<&TextSize>
Start index bound. Read more
1.35.0 · sourcefn contains<U>(&self, item: &U) -> boolwhere
T: PartialOrd<U>,
U: PartialOrd<T> + ?Sized,
fn contains<U>(&self, item: &U) -> boolwhere
T: PartialOrd<U>,
U: PartialOrd<T> + ?Sized,
Returns true
if item
is contained in the range. Read more
sourceimpl<S> SubAssign<S> for TextSizewhere
TextSize: Sub<S>,
<TextSize as Sub<S>>::Output == TextSize,
impl<S> SubAssign<S> for TextSizewhere
TextSize: Sub<S>,
<TextSize as Sub<S>>::Output == TextSize,
sourcefn sub_assign(&mut self, rhs: S)
fn sub_assign(&mut self, rhs: S)
Performs the -=
operation. Read more
sourceimpl TryFrom<usize> for TextSize
impl TryFrom<usize> for TextSize
type Error = TryFromIntError
type Error = TryFromIntError
The type returned in the event of a conversion error.
impl Copy for TextSize
impl Eq for TextSize
impl StructuralEq for TextSize
impl StructuralPartialEq for TextSize
Auto Trait Implementations
impl RefUnwindSafe for TextSize
impl Send for TextSize
impl Sync for TextSize
impl Unpin for TextSize
impl UnwindSafe for TextSize
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more