Unnamed repository; edit this file 'description' to name the repository.
| -rw-r--r-- | lib/text-size/src/traits.rs | 20 | ||||
| -rw-r--r-- | lib/text-size/tests/constructors.rs | 31 |
2 files changed, 31 insertions, 20 deletions
diff --git a/lib/text-size/src/traits.rs b/lib/text-size/src/traits.rs index 018a62cb76..6f3462bee5 100644 --- a/lib/text-size/src/traits.rs +++ b/lib/text-size/src/traits.rs @@ -34,23 +34,3 @@ impl TextSized for char { (self.len_utf8() as u32).into() } } - -// assertion shape from static_assertions::assert_impl_all! -const _: fn() = || { - use std::borrow::Cow; - - fn assert_impl<T: TextSized>() {} - - assert_impl::<&String>(); - assert_impl::<&Cow<str>>(); - - struct StringLike {} - impl Deref for StringLike { - type Target = str; - fn deref(&self) -> &str { - unreachable!() - } - } - - assert_impl::<&StringLike>(); -}; diff --git a/lib/text-size/tests/constructors.rs b/lib/text-size/tests/constructors.rs new file mode 100644 index 0000000000..eba587b539 --- /dev/null +++ b/lib/text-size/tests/constructors.rs @@ -0,0 +1,31 @@ +use { + std::{borrow::Cow, ops::Deref}, + text_size::*, +}; + +struct StringLike<'a>(&'a str); + +impl Deref for StringLike<'_> { + type Target = str; + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +#[test] +fn main() { + let s = ""; + let _ = TextSize::of(&s); + + let s = String::new(); + let _ = TextSize::of(&s); + + let s = Cow::Borrowed(""); + let _ = TextSize::of(&s); + + let s = Cow::Owned(String::new()); + let _ = TextSize::of(&s); + + let s = StringLike(""); + let _ = TextSize::of(&s); +} |