pub struct TextSize { /* private fields */ }
Expand description
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§
source§impl TextSize
impl TextSize
sourcepub fn of<T>(text: T) -> TextSizewhere
T: TextLen,
pub fn of<T>(text: T) -> TextSizewhere
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));
source§impl TextSize
impl TextSize
Methods to act like a primitive integer type, where reasonably applicable.
sourcepub const fn checked_add(self, rhs: TextSize) -> Option<TextSize>
pub const fn checked_add(self, rhs: TextSize) -> Option<TextSize>
Checked addition. Returns None
if overflow occurred.
sourcepub const fn checked_sub(self, rhs: TextSize) -> Option<TextSize>
pub const fn checked_sub(self, rhs: TextSize) -> Option<TextSize>
Checked subtraction. Returns None
if overflow occurred.
Trait Implementations§
source§impl<A> AddAssign<A> for TextSize
impl<A> AddAssign<A> for TextSize
source§fn add_assign(&mut self, rhs: A)
fn add_assign(&mut self, rhs: A)
+=
operation. Read moresource§impl Ord for TextSize
impl Ord for TextSize
source§impl PartialEq for TextSize
impl PartialEq for TextSize
source§impl PartialOrd for TextSize
impl PartialOrd for TextSize
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl RangeBounds<TextSize> for TextRange
impl RangeBounds<TextSize> for TextRange
source§impl<S> SubAssign<S> for TextSize
impl<S> SubAssign<S> for TextSize
source§fn sub_assign(&mut self, rhs: S)
fn sub_assign(&mut self, rhs: S)
-=
operation. Read moresource§impl TryFrom<usize> for TextSize
impl TryFrom<usize> for TextSize
§type Error = TryFromIntError
type Error = TryFromIntError
impl Copy for TextSize
impl Eq for TextSize
impl StructuralPartialEq for TextSize
Auto Trait Implementations§
impl Freeze for TextSize
impl RefUnwindSafe for TextSize
impl Send for TextSize
impl Sync for TextSize
impl Unpin for TextSize
impl UnwindSafe for TextSize
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)