Struct ra_ap_syntax::TextSize
[−]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
pub fn of<T>(text: T) -> TextSize where
T: TextLen,
pub fn of<T>(text: T) -> TextSize where
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));
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
impl<A> AddAssign<A> for TextSize where
TextSize: Add<A>,
<TextSize as Add<A>>::Output == TextSize,
impl<A> AddAssign<A> for TextSize where
TextSize: Add<A>,
<TextSize as Add<A>>::Output == TextSize,
fn add_assign(&mut self, rhs: A)
fn add_assign(&mut self, rhs: A)
Performs the +=
operation. Read more
sourceimpl AddAssign<Delta<TextSize>> for TextSize
impl AddAssign<Delta<TextSize>> for TextSize
sourcefn add_assign(&mut self, rhs: Delta<TextSize>)
fn add_assign(&mut self, rhs: Delta<TextSize>)
Performs the +=
operation. Read more
impl 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) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
impl PartialOrd<TextSize> for TextSize
impl PartialOrd<TextSize> for TextSize
fn 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
impl RangeBounds<TextSize> for TextRange
impl RangeBounds<TextSize> for TextRange
impl<S> SubAssign<S> for TextSize where
TextSize: Sub<S>,
<TextSize as Sub<S>>::Output == TextSize,
impl<S> SubAssign<S> for TextSize where
TextSize: Sub<S>,
<TextSize as Sub<S>>::Output == TextSize,
fn sub_assign(&mut self, rhs: S)
fn sub_assign(&mut self, rhs: S)
Performs the -=
operation. Read more
impl 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.
fn try_from(value: usize) -> Result<TextSize, TryFromIntError>
fn try_from(value: usize) -> Result<TextSize, TryFromIntError>
Performs the conversion.
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 T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
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
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.