1 use {crate::TextSize, std::convert::TryInto}
;
3 use priv_in_pub
::Sealed
;
8 /// Primitives with a textual length that can be passed to [`TextSize::of`].
9 pub trait TextLen
: Copy
+ Sealed
{
10 /// The textual length of this primitive.
11 fn text_len(self) -> TextSize
;
14 impl Sealed
for &'_
str {}
15 impl TextLen
for &'_
str {
17 fn text_len(self) -> TextSize
{
18 self.len().try_into().unwrap()
22 impl Sealed
for &'_ String {}
23 impl TextLen
for &'_ String
{
25 fn text_len(self) -> TextSize
{
26 self.as_str().text_len()
30 impl Sealed
for char {}
31 impl TextLen
for char {
33 fn text_len(self) -> TextSize
{
34 (self.len_utf8() as u32).into()