Struct rnix::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.

Implementations

impl TextSize

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

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.

impl<'_> Add<&'_ TextSize> for TextRange

type Output = TextRange

The resulting type after applying the + operator.

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

type Output = TextSize

The resulting type after applying the + operator.

impl Add<TextSize> for TextRange

type Output = TextRange

The resulting type after applying the + operator.

impl Add<TextSize> for TextSize

type Output = TextSize

The resulting type after applying the + operator.

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

impl Clone for TextSize

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

impl Ord for TextSize

impl PartialEq<TextSize> for TextSize

impl PartialOrd<TextSize> for TextSize

impl RangeBounds<TextSize> for TextRange

impl StructuralEq for TextSize

impl StructuralPartialEq for TextSize

impl<'_> Sub<&'_ TextSize> for TextRange

type Output = TextRange

The resulting type after applying the - operator.

impl<'_> Sub<&'_ TextSize> for TextSize

type Output = TextSize

The resulting type after applying the - operator.

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

type Output = TextSize

The resulting type after applying the - operator.

impl Sub<TextSize> for TextRange

type Output = TextRange

The resulting type after applying the - operator.

impl Sub<TextSize> for TextSize

type Output = TextSize

The resulting type after applying the - operator.

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

impl<A> Sum<A> for TextSize where
    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.

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.