pub struct TextSize {
pub(crate) raw: u32,
}
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.
Fields§
§raw: u32
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<'de> Deserialize<'de> for TextSize
impl<'de> Deserialize<'de> for TextSize
§fn deserialize<D>(
deserializer: D,
) -> Result<TextSize, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<TextSize, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
source§impl From<LexerPosition> for TextSize
impl From<LexerPosition> for TextSize
source§fn from(value: LexerPosition) -> Self
fn from(value: LexerPosition) -> Self
§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 Serialize for TextSize
impl Serialize for TextSize
§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
§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
)