mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-12-27 16:07:46 +00:00
TextSized is not meant to be used directly...
so rename it to a name more distinct from TextSize.
This commit is contained in:
parent
3d1a768d29
commit
ade5c7b7d6
@ -12,7 +12,7 @@ mod traits;
|
||||
#[cfg(feature = "serde")]
|
||||
mod serde_impls;
|
||||
|
||||
pub use crate::{range::TextRange, size::TextSize, traits::TextSized};
|
||||
pub use crate::{range::TextRange, size::TextSize, traits::LenTextSize};
|
||||
|
||||
#[cfg(target_pointer_width = "16")]
|
||||
compile_error!("text-size assumes usize >= u32 and does not work on 16-bit targets");
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use {
|
||||
crate::TextSized,
|
||||
crate::LenTextSize,
|
||||
std::{
|
||||
convert::TryFrom,
|
||||
fmt, iter,
|
||||
@ -42,8 +42,8 @@ impl fmt::Debug for TextSize {
|
||||
impl TextSize {
|
||||
/// The text size of some text-like object.
|
||||
#[inline]
|
||||
pub fn of(text: impl TextSized) -> TextSize {
|
||||
text.text_size()
|
||||
pub fn of(text: impl LenTextSize) -> TextSize {
|
||||
text.len_text_size()
|
||||
}
|
||||
|
||||
/// A size of zero.
|
||||
|
||||
@ -4,33 +4,33 @@ use {
|
||||
};
|
||||
|
||||
/// Text-like structures that have a text size.
|
||||
pub trait TextSized: Copy {
|
||||
pub trait LenTextSize: Copy {
|
||||
/// The size of this text-alike.
|
||||
fn text_size(self) -> TextSize;
|
||||
fn len_text_size(self) -> TextSize;
|
||||
}
|
||||
|
||||
impl TextSized for &'_ str {
|
||||
impl LenTextSize for &'_ str {
|
||||
#[inline]
|
||||
fn text_size(self) -> TextSize {
|
||||
fn len_text_size(self) -> TextSize {
|
||||
self.len()
|
||||
.try_into()
|
||||
.unwrap_or_else(|_| panic!("string too large ({}) for TextSize", self.len()))
|
||||
}
|
||||
}
|
||||
|
||||
impl<D> TextSized for &'_ D
|
||||
impl<D> LenTextSize for &'_ D
|
||||
where
|
||||
D: Deref<Target = str>,
|
||||
{
|
||||
#[inline]
|
||||
fn text_size(self) -> TextSize {
|
||||
self.deref().text_size()
|
||||
fn len_text_size(self) -> TextSize {
|
||||
self.deref().len_text_size()
|
||||
}
|
||||
}
|
||||
|
||||
impl TextSized for char {
|
||||
impl LenTextSize for char {
|
||||
#[inline]
|
||||
fn text_size(self) -> TextSize {
|
||||
fn len_text_size(self) -> TextSize {
|
||||
(self.len_utf8() as u32).into()
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user