Skip to content

Commit 63cbf15

Browse files
committed
add recursive impl for TextSized
1 parent 246660c commit 63cbf15

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/traits.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use {crate::TextSize, std::convert::TryInto};
1+
use {
2+
crate::TextSize,
3+
std::{convert::TryInto, ops::Deref},
4+
};
25

36
/// Text-like structures that have a text size.
47
pub trait TextSized: Copy {
@@ -15,6 +18,17 @@ impl TextSized for &'_ str {
1518
}
1619
}
1720

21+
impl<D> TextSized for &'_ D
22+
where
23+
D: Deref,
24+
for<'a> &'a D::Target: TextSized,
25+
{
26+
#[inline]
27+
fn text_size(self) -> TextSize {
28+
self.deref().text_size()
29+
}
30+
}
31+
1832
impl TextSized for char {
1933
#[inline]
2034
fn text_size(self) -> TextSize {

0 commit comments

Comments
 (0)