Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'lib/text-size/src/traits.rs')
-rw-r--r--lib/text-size/src/traits.rs48
1 files changed, 8 insertions, 40 deletions
diff --git a/lib/text-size/src/traits.rs b/lib/text-size/src/traits.rs
index c0adacd92b..d0bb6c1f66 100644
--- a/lib/text-size/src/traits.rs
+++ b/lib/text-size/src/traits.rs
@@ -1,7 +1,4 @@
-use {
- crate::TextSize,
- std::{borrow::Cow, convert::TryInto, rc::Rc, sync::Arc},
-};
+use {crate::TextSize, std::convert::TryInto};
use priv_in_pub::Sealed;
mod priv_in_pub {
@@ -22,47 +19,18 @@ impl TextLen for &'_ str {
}
}
-impl Sealed for char {}
-impl TextLen for char {
+impl Sealed for &'_ String {}
+impl TextLen for &'_ String {
#[inline]
fn text_len(self) -> TextSize {
- (self.len_utf8() as u32).into()
+ self.as_str().text_len()
}
}
-impl<D> Sealed for &'_ D where D: TextLen + Copy {}
-impl<D> TextLen for &'_ D
-where
- D: TextLen + Copy,
-{
+impl Sealed for char {}
+impl TextLen for char {
+ #[inline]
fn text_len(self) -> TextSize {
- D::text_len(*self)
+ (self.len_utf8() as u32).into()
}
}
-
-// Because we could not find a smart blanket impl to do this automatically and
-// cleanly (rust-analyzer/text-size#36), just provide a bunch of manual impls.
-// If a standard type fits in this macro and you need it to impl TextLen, just
-// open a PR and we are likely to accept it. Or convince Rust to deref to &str.
-macro_rules! impl_textlen_for_string {
- ($($ty:ty),+ $(,)?) => {$(
- impl Sealed for $ty {}
- impl TextLen for $ty {
- #[inline]
- fn text_len(self) -> TextSize {
- <&str>::text_len(self)
- }
- }
- )+};
-}
-
-impl_textlen_for_string! {
- &Box<str>,
- &String,
- &Cow<'_, str>,
- &Cow<'_, String>,
- &Arc<str>,
- &Arc<String>,
- &Rc<str>,
- &Rc<String>,
-}