Unnamed repository; edit this file 'description' to name the repository.
add recursive impl for TextSized
| -rw-r--r-- | lib/text-size/src/traits.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/text-size/src/traits.rs b/lib/text-size/src/traits.rs index 7064dbc658..6c30549edc 100644 --- a/lib/text-size/src/traits.rs +++ b/lib/text-size/src/traits.rs @@ -1,4 +1,7 @@ -use {crate::TextSize, std::convert::TryInto}; +use { + crate::TextSize, + std::{convert::TryInto, ops::Deref}, +}; /// Text-like structures that have a text size. pub trait TextSized: Copy { @@ -15,6 +18,17 @@ impl TextSized for &'_ str { } } +impl<D> TextSized for &'_ D +where + D: Deref, + for<'a> &'a D::Target: TextSized, +{ + #[inline] + fn text_size(self) -> TextSize { + self.deref().text_size() + } +} + impl TextSized for char { #[inline] fn text_size(self) -> TextSize { |