Struct TextSize
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§
§impl TextSize
impl TextSize
pub 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));
§impl TextSize
impl TextSize
Methods to act like a primitive integer type, where reasonably applicable.
pub 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.
pub 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§
§impl<A> AddAssign<A> for TextSize
impl<A> AddAssign<A> for TextSize
§fn add_assign(&mut self, rhs: A)
fn add_assign(&mut self, rhs: A)
+=
operation. Read more§impl AddAssign<Delta<TextSize>> for TextSize
impl AddAssign<Delta<TextSize>> for TextSize
§fn add_assign(&mut self, rhs: Delta<TextSize>)
fn add_assign(&mut self, rhs: Delta<TextSize>)
+=
operation. Read more§impl Ord for TextSize
impl Ord for TextSize
§impl PartialOrd for TextSize
impl PartialOrd for TextSize
§impl RangeBounds<TextSize> for TextRange
impl RangeBounds<TextSize> for TextRange
§impl<S> SubAssign<S> for TextSize
impl<S> SubAssign<S> for TextSize
§fn sub_assign(&mut self, rhs: S)
fn sub_assign(&mut self, rhs: S)
-=
operation. Read more§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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more