Struct ra_ap_ide::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 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
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 TextSize
type Output = TextSize
The resulting type after applying the +
operator.
pub fn add(self, other: &TextSize) -> TextSize
impl<'_> Add<&'_ TextSize> for TextRange
type Output = TextRange
The resulting type after applying the +
operator.
pub fn add(self, other: &TextSize) -> TextRange
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.
pub fn add(self, other: T) -> TextSize
impl Add<TextSize> for TextSize
type Output = TextSize
The resulting type after applying the +
operator.
pub fn add(self, other: TextSize) -> TextSize
impl Add<TextSize> for TextRange
type Output = TextRange
The resulting type after applying the +
operator.
pub 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,
pub fn add_assign(&mut self, rhs: A)
impl Clone for TextSize
pub fn clone(&self) -> TextSize
pub 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
pub fn hash<__H>(&self, state: &mut __H) where
__H: Hasher,
__H: Hasher,
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for TextSize
pub fn cmp(&self, other: &TextSize) -> Ordering
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl PartialEq<TextSize> for TextSize
impl PartialOrd<TextSize> for TextSize
pub fn partial_cmp(&self, other: &TextSize) -> Option<Ordering>
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl RangeBounds<TextSize> for TextRange
pub fn start_bound(&self) -> Bound<&TextSize>
pub fn end_bound(&self) -> Bound<&TextSize>
pub fn assert_len(self, len: usize) -> Range<usize> where
Self: RangeBounds<usize>,
[src]
Self: RangeBounds<usize>,
pub 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 StructuralEq for TextSize
impl StructuralPartialEq for TextSize
impl<'_> Sub<&'_ TextSize> for TextSize
type Output = TextSize
The resulting type after applying the -
operator.
pub fn sub(self, other: &TextSize) -> TextSize
impl<'_> Sub<&'_ TextSize> for TextRange
type Output = TextRange
The resulting type after applying the -
operator.
pub 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.
pub fn sub(self, other: T) -> TextSize
impl Sub<TextSize> for TextSize
type Output = TextSize
The resulting type after applying the -
operator.
pub fn sub(self, other: TextSize) -> TextSize
impl Sub<TextSize> for TextRange
type Output = TextRange
The resulting type after applying the -
operator.
pub fn sub(self, offset: TextSize) -> TextRange
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,
pub 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.
pub fn try_from(value: usize) -> Result<TextSize, TryFromIntError>
Auto Trait Implementations
impl RefUnwindSafe for TextSize
[src]
impl Send for TextSize
[src]
impl Sync for TextSize
[src]
impl Unpin for TextSize
[src]
impl UnwindSafe for TextSize
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Any for T where
T: Any,
T: Any,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Cast for T
pub fn cast<U>(self, interner: &<U as HasInterner>::Interner) -> U where
Self: CastTo<U>,
U: HasInterner,
Self: CastTo<U>,
U: HasInterner,
impl<T> CloneAny for T where
T: Clone + Any,
T: Clone + Any,
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
pub fn equivalent(&self, key: &K) -> bool
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<M> Measure for M where
M: Debug + PartialOrd<M> + Add<M, Output = M> + Default + Clone,
[src]
M: Debug + PartialOrd<M> + Add<M, Output = M> + Default + Clone,
impl<N> NodeTrait for N where
N: Copy + Ord + Hash,
[src]
N: Copy + Ord + Hash,
impl<T> Pointable for T
pub const ALIGN: usize
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
pub unsafe fn drop(ptr: usize)
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub 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.
pub 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>,