[−]Struct ra_ap_syntax::TextSize
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
pub fn of<T>(text: T) -> TextSize where
T: TextLen,
T: TextLen,
The text size of some text-like object.
Accepts char
, &str
, and references to any custom string-like type
that dereferences to str
. Types that don't dereference to str
but
want to be usable in this constructor can implement [TextLen
].
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
Methods to act like a primitive integer type, where reasonably applicable.
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>
Checked subtraction. Returns None
if overflow occurred.
Trait Implementations
impl<'_> Add<&'_ TextSize> for TextRange
type Output = TextRange
The resulting type after applying the +
operator.
fn add(self, other: &TextSize) -> TextRange
impl<'_> Add<&'_ TextSize> for TextSize
type Output = TextSize
The resulting type after applying the +
operator.
fn add(self, other: &TextSize) -> TextSize
impl<'_, T> Add<T> for &'_ TextSize where
TextSize: Add<T>,
<TextSize as Add<T>>::Output == TextSize,
TextSize: Add<T>,
<TextSize as Add<T>>::Output == TextSize,
type Output = TextSize
The resulting type after applying the +
operator.
fn add(self, other: T) -> TextSize
impl Add<TextSize> for TextSize
type Output = TextSize
The resulting type after applying the +
operator.
fn add(self, other: TextSize) -> TextSize
impl Add<TextSize> for TextRange
type Output = TextRange
The resulting type after applying the +
operator.
fn add(self, offset: TextSize) -> TextRange
impl<A> AddAssign<A> for TextSize where
TextSize: Add<A>,
<TextSize as Add<A>>::Output == TextSize,
TextSize: Add<A>,
<TextSize as Add<A>>::Output == TextSize,
fn add_assign(&mut self, rhs: A)
impl Clone for TextSize
fn clone(&self) -> TextSize
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for TextSize
impl Debug for TextSize
impl Default for TextSize
impl Eq for TextSize
impl From<u32> for TextSize
impl Hash for TextSize
fn hash<__H>(&self, state: &mut __H) where
__H: Hasher,
__H: Hasher,
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for TextSize
fn cmp(&self, other: &TextSize) -> Ordering
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<TextSize> for TextSize
impl PartialOrd<TextSize> for TextSize
fn partial_cmp(&self, other: &TextSize) -> Option<Ordering>
fn lt(&self, other: &TextSize) -> bool
fn le(&self, other: &TextSize) -> bool
fn gt(&self, other: &TextSize) -> bool
fn ge(&self, other: &TextSize) -> bool
impl RangeBounds<TextSize> for TextRange
fn start_bound(&self) -> Bound<&TextSize>
fn end_bound(&self) -> Bound<&TextSize>
fn contains<U>(&self, item: &U) -> bool where
T: PartialOrd<U>,
U: PartialOrd<T> + ?Sized,
1.35.0[src]
T: PartialOrd<U>,
U: PartialOrd<T> + ?Sized,
impl<'_> Sub<&'_ TextSize> for TextSize
type Output = TextSize
The resulting type after applying the -
operator.
fn sub(self, other: &TextSize) -> TextSize
impl<'_> Sub<&'_ TextSize> for TextRange
type Output = TextRange
The resulting type after applying the -
operator.
fn sub(self, other: &TextSize) -> TextRange
impl<'_, T> Sub<T> for &'_ TextSize where
TextSize: Sub<T>,
<TextSize as Sub<T>>::Output == TextSize,
TextSize: Sub<T>,
<TextSize as Sub<T>>::Output == TextSize,
type Output = TextSize
The resulting type after applying the -
operator.
fn sub(self, other: T) -> TextSize
impl Sub<TextSize> for TextRange
type Output = TextRange
The resulting type after applying the -
operator.
fn sub(self, offset: TextSize) -> TextRange
impl Sub<TextSize> for TextSize
type Output = TextSize
The resulting type after applying the -
operator.
fn sub(self, other: TextSize) -> TextSize
impl<S> SubAssign<S> for TextSize where
TextSize: Sub<S>,
<TextSize as Sub<S>>::Output == TextSize,
TextSize: Sub<S>,
<TextSize as Sub<S>>::Output == TextSize,
fn sub_assign(&mut self, rhs: S)
impl<A> Sum<A> for TextSize where
TextSize: Add<A>,
<TextSize as Add<A>>::Output == TextSize,
TextSize: Add<A>,
<TextSize as Add<A>>::Output == TextSize,
impl TryFrom<usize> for TextSize
type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(value: usize) -> Result<TextSize, TryFromIntError>
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
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,