Struct rowan::TextSize [−][src]
pub struct TextSize { /* fields omitted */ }
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
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));
Methods to act like a primitive integer type, where reasonably applicable.
Checked addition. Returns None
if overflow occurred.
Checked subtraction. Returns None
if overflow occurred.
Trait Implementations
Performs the +=
operation. Read more
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Start index bound. Read more
1.35.0[src]fn contains<U>(&self, item: &U) -> bool where
T: PartialOrd<U>,
U: PartialOrd<T> + ?Sized,
fn contains<U>(&self, item: &U) -> bool where
T: PartialOrd<U>,
U: PartialOrd<T> + ?Sized,
Returns true
if item
is contained in the range. Read more
Performs the -=
operation. Read more
type Error = TryFromIntError
type Error = TryFromIntError
The type returned in the event of a conversion error.
Auto Trait Implementations
impl RefUnwindSafe for TextSize
impl UnwindSafe for TextSize
Blanket Implementations
Mutably borrows from an owned value. Read more