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
impl TextSize
impl TextSize
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));
impl TextSize
impl TextSize
Methods to act like a primitive integer type, where reasonably applicable.
pub fn checked_add(self, rhs: TextSize) -> Option<TextSize>
pub fn checked_add(self, rhs: TextSize) -> Option<TextSize>
Checked addition. Returns None
if overflow occurred.
pub 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
pub fn add_assign(&mut self, rhs: A)
pub fn add_assign(&mut self, rhs: A)
Performs the +=
operation. Read more
pub fn add_assign(&mut self, rhs: Delta<TextSize>)
pub fn add_assign(&mut self, rhs: Delta<TextSize>)
Performs the +=
operation. Read more
impl PartialOrd<TextSize> for TextSize
impl PartialOrd<TextSize> for TextSize
pub fn partial_cmp(&self, other: &TextSize) -> Option<Ordering>
pub fn partial_cmp(&self, other: &TextSize) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl RangeBounds<TextSize> for TextRange
impl RangeBounds<TextSize> for TextRange
pub fn start_bound(&self) -> Bound<&TextSize>
pub fn start_bound(&self) -> Bound<&TextSize>
Start index bound. Read more
1.35.0 · sourcefn contains<U>(&self, item: &U) -> bool where
T: PartialOrd<U>,
U: PartialOrd<T> + ?Sized,
fn contains<U>(&self, item: &U) -> bool where
T: PartialOrd<U>,
U: PartialOrd<T> + ?Sized,
Returns true
if item
is contained in the range. Read more
pub fn sub_assign(&mut self, rhs: S)
pub fn sub_assign(&mut self, rhs: S)
Performs the -=
operation. Read more
type Error = TryFromIntError
type Error = TryFromIntError
The type returned in the event of a conversion error.
pub fn try_from(value: usize) -> Result<TextSize, TryFromIntError>
pub fn try_from(value: usize) -> Result<TextSize, TryFromIntError>
Performs the conversion.
impl StructuralEq for TextSize
impl StructuralPartialEq for TextSize
Auto Trait Implementations
impl RefUnwindSafe for TextSize
impl UnwindSafe for TextSize
Blanket Implementations
Mutably borrows from an owned value. Read more
fn cast<U>(self, interner: <U as HasInterner>::Interner) -> U where
Self: CastTo<U>,
U: HasInterner,
fn cast<U>(self, interner: <U as HasInterner>::Interner) -> U where
Self: CastTo<U>,
U: HasInterner,
Cast a value to type U
using CastTo
.
Compare self to key
and return true
if they are equal.
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more