[−][src]Struct text_size::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
[src]
pub fn of<T: TextLen>(text: T) -> TextSize
[src]
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
[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.
fn add(self, other: &TextSize) -> TextRange
[src]
impl<'_> Add<&'_ TextSize> for TextSize
[src]
type Output = TextSize
The resulting type after applying the +
operator.
fn add(self, other: &TextSize) -> TextSize
[src]
impl<T, '_> Add<T> for &'_ TextSize where
TextSize: Add<T, Output = TextSize>,
[src]
TextSize: Add<T, Output = TextSize>,
type Output = TextSize
The resulting type after applying the +
operator.
fn add(self, other: T) -> TextSize
[src]
impl Add<TextSize> for TextRange
[src]
type Output = TextRange
The resulting type after applying the +
operator.
fn add(self, offset: TextSize) -> TextRange
[src]
impl Add<TextSize> for TextSize
[src]
type Output = TextSize
The resulting type after applying the +
operator.
fn add(self, other: TextSize) -> TextSize
[src]
impl<A> AddAssign<A> for TextSize where
TextSize: Add<A, Output = TextSize>,
[src]
TextSize: Add<A, Output = TextSize>,
fn add_assign(&mut self, rhs: A)
[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<TextSize> for u32
[src]
impl From<TextSize> for usize
[src]
impl From<u32> for TextSize
[src]
impl Hash for TextSize
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for TextSize
[src]
fn cmp(&self, other: &TextSize) -> Ordering
[src]
#[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
[src]
impl PartialOrd<TextSize> for TextSize
[src]
fn partial_cmp(&self, other: &TextSize) -> Option<Ordering>
[src]
fn lt(&self, other: &TextSize) -> bool
[src]
fn le(&self, other: &TextSize) -> bool
[src]
fn gt(&self, other: &TextSize) -> bool
[src]
fn ge(&self, other: &TextSize) -> bool
[src]
impl RangeBounds<TextSize> for TextRange
[src]
fn start_bound(&self) -> Bound<&TextSize>
[src]
fn end_bound(&self) -> Bound<&TextSize>
[src]
fn assert_len(self, len: usize) -> Range<usize> where
Self: RangeBounds<usize>,
[src]
Self: RangeBounds<usize>,
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
[src]
impl StructuralPartialEq for TextSize
[src]
impl<'_> Sub<&'_ TextSize> for TextRange
[src]
type Output = TextRange
The resulting type after applying the -
operator.
fn sub(self, other: &TextSize) -> TextRange
[src]
impl<'_> Sub<&'_ TextSize> for TextSize
[src]
type Output = TextSize
The resulting type after applying the -
operator.
fn sub(self, other: &TextSize) -> TextSize
[src]
impl<T, '_> Sub<T> for &'_ TextSize where
TextSize: Sub<T, Output = TextSize>,
[src]
TextSize: Sub<T, Output = TextSize>,
type Output = TextSize
The resulting type after applying the -
operator.
fn sub(self, other: T) -> TextSize
[src]
impl Sub<TextSize> for TextRange
[src]
type Output = TextRange
The resulting type after applying the -
operator.
fn sub(self, offset: TextSize) -> TextRange
[src]
impl Sub<TextSize> for TextSize
[src]
type Output = TextSize
The resulting type after applying the -
operator.
fn sub(self, other: TextSize) -> TextSize
[src]
impl<S> SubAssign<S> for TextSize where
TextSize: Sub<S, Output = TextSize>,
[src]
TextSize: Sub<S, Output = TextSize>,
fn sub_assign(&mut self, rhs: S)
[src]
impl<A> Sum<A> for TextSize where
TextSize: Add<A, Output = TextSize>,
[src]
TextSize: Add<A, Output = TextSize>,
impl TryFrom<usize> for TextSize
[src]
type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(value: usize) -> Result<Self, TryFromIntError>
[src]
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,
pub 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.
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>,