[][src]Struct rowan::TextSize

pub struct TextSize { /* fields omitted */ }

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.

Methods

impl TextSize[src]

pub fn of<T>(text: T) -> TextSize where
    T: TextLen
[src]

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[src]

Methods to act like a primitive integer type, where reasonably applicable.

pub fn checked_add(self, rhs: TextSize) -> Option<TextSize>[src]

Checked addition. Returns None if overflow occurred.

pub fn checked_sub(self, rhs: TextSize) -> Option<TextSize>[src]

Checked subtraction. Returns None if overflow occurred.

Trait Implementations

impl<'_> Add<&'_ TextSize> for TextRange[src]

type Output = TextRange

The resulting type after applying the + operator.

impl<'_> Add<&'_ TextSize> for TextSize[src]

type Output = TextSize

The resulting type after applying the + operator.

impl<'_, T> Add<T> for &'_ TextSize where
    TextSize: Add<T>,
    <TextSize as Add<T>>::Output == TextSize
[src]

type Output = TextSize

The resulting type after applying the + operator.

impl Add<TextSize> for TextSize[src]

type Output = TextSize

The resulting type after applying the + operator.

impl Add<TextSize> for TextRange[src]

type Output = TextRange

The resulting type after applying the + operator.

impl<A> AddAssign<A> for TextSize where
    TextSize: Add<A>,
    <TextSize as Add<A>>::Output == TextSize
[src]

impl Clone for TextSize[src]

impl Copy for TextSize[src]

impl Debug for TextSize[src]

impl Default for TextSize[src]

impl Eq for TextSize[src]

impl From<u32> for TextSize[src]

impl Hash for TextSize[src]

impl Ord for TextSize[src]

impl PartialEq<TextSize> for TextSize[src]

impl PartialOrd<TextSize> for TextSize[src]

impl RangeBounds<TextSize> for TextRange[src]

impl StructuralEq for TextSize[src]

impl StructuralPartialEq for TextSize[src]

impl<'_> Sub<&'_ TextSize> for TextSize[src]

type Output = TextSize

The resulting type after applying the - operator.

impl<'_> Sub<&'_ TextSize> for TextRange[src]

type Output = TextRange

The resulting type after applying the - operator.

impl<'_, T> Sub<T> for &'_ TextSize where
    TextSize: Sub<T>,
    <TextSize as Sub<T>>::Output == TextSize
[src]

type Output = TextSize

The resulting type after applying the - operator.

impl Sub<TextSize> for TextSize[src]

type Output = TextSize

The resulting type after applying the - operator.

impl Sub<TextSize> for TextRange[src]

type Output = TextRange

The resulting type after applying the - operator.

impl<S> SubAssign<S> for TextSize where
    TextSize: Sub<S>,
    <TextSize as Sub<S>>::Output == TextSize
[src]

impl<A> Sum<A> for TextSize where
    TextSize: Add<A>,
    <TextSize as Add<A>>::Output == TextSize
[src]

impl TryFrom<usize> for TextSize[src]

type Error = TryFromIntError

The type returned in the event of a conversion error.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.