[−][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][+]
impl<'_> Add<&'_ TextSize> for TextSize
[src][+]
impl<T, '_> Add<T> for &'_ TextSize where
TextSize: Add<T, Output = TextSize>,
[src][+]
TextSize: Add<T, Output = TextSize>,
impl Add<TextSize> for TextRange
[src][+]
impl Add<TextSize> for TextSize
[src][+]
impl<A> AddAssign<A> for TextSize where
TextSize: Add<A, Output = TextSize>,
[src][+]
TextSize: Add<A, Output = TextSize>,
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][+]
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 TextRange
[src][+]
impl<'_> Sub<&'_ TextSize> for TextSize
[src][+]
impl<T, '_> Sub<T> for &'_ TextSize where
TextSize: Sub<T, Output = TextSize>,
[src][+]
TextSize: Sub<T, Output = TextSize>,
impl Sub<TextSize> for TextRange
[src][+]
impl Sub<TextSize> for TextSize
[src][+]
impl<S> SubAssign<S> for TextSize where
TextSize: Sub<S, Output = TextSize>,
[src][+]
TextSize: Sub<S, Output = TextSize>,
impl<A> Sum<A> for TextSize where
TextSize: Add<A, Output = TextSize>,
[src][+]
TextSize: Add<A, Output = TextSize>,
impl TryFrom<usize> for TextSize
[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,
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,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src][+]
U: Into<T>,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src][+]
U: TryFrom<T>,