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) -> TextSize where
T: TextLen,
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
impl TextSize
Methods to act like a primitive integer type, where reasonably applicable.
pub fn checked_add(self, rhs: TextSize) -> Option<TextSize>
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>
pub fn checked_sub(self, rhs: TextSize) -> Option<TextSize>
Checked subtraction. Returns None
if overflow occurred.
Trait Implementations
impl<A> AddAssign<A> for TextSize where
TextSize: Add<A>,
<TextSize as Add<A>>::Output == TextSize,
impl<A> AddAssign<A> for TextSize where
TextSize: Add<A>,
<TextSize as Add<A>>::Output == TextSize,
fn add_assign(&mut self, rhs: A)
fn add_assign(&mut self, rhs: A)
Performs the +=
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>)
Performs the +=
operation. Read more
impl Ord for TextSize
impl Ord for TextSize
impl PartialOrd<TextSize> for TextSize
impl PartialOrd<TextSize> for TextSize
fn partial_cmp(&self, other: &TextSize) -> Option<Ordering>
fn partial_cmp(&self, other: &TextSize) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl RangeBounds<TextSize> for TextRange
impl RangeBounds<TextSize> for TextRange
impl<S> SubAssign<S> for TextSize where
TextSize: Sub<S>,
<TextSize as Sub<S>>::Output == TextSize,
impl<S> SubAssign<S> for TextSize where
TextSize: Sub<S>,
<TextSize as Sub<S>>::Output == TextSize,
fn sub_assign(&mut self, rhs: S)
fn sub_assign(&mut self, rhs: S)
Performs the -=
operation. Read more
impl TryFrom<usize> for TextSize
impl TryFrom<usize> for TextSize
type Error = TryFromIntError
type Error = TryFromIntError
The type returned in the event of a conversion error.
fn try_from(value: usize) -> Result<TextSize, TryFromIntError>
fn try_from(value: usize) -> Result<TextSize, TryFromIntError>
Performs the conversion.
impl Copy for TextSize
impl Eq for TextSize
impl StructuralEq for TextSize
impl StructuralPartialEq for TextSize
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Cast for T
impl<T> Cast for T
fn cast<U>(self, interner: <U as HasInterner>::Interner) -> U where
Self: CastTo<U>,
U: HasInterner,
fn cast<U>(self, interner: <U as HasInterner>::Interner) -> U where
Self: CastTo<U>,
U: HasInterner,
Cast a value to type U
using CastTo
.
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more