You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
23: Add a deref-removing impl for TextSized r=CAD97 a=CAD97
Notably, given `s: &SmolStr`, `TextSize::of(s)` does not work, where `TextUnit::of_str(s)` did, because the concrete type could be deref-coerced to. (It's probably a limitation of the language that deref coersion does not apply here, but it's one we have to live with.)
So we provide a blanket impl for any type that derefs (directly) to `str`.
Alternatively, we can provide a deeper blanket impl that derefs any number of references recursively [[playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=008b5e0c2edd332b34b3efa42ce2a40a)]:
```rust
impl<D> TextSized for &'_ D
where
D: Deref,
for<'a> &'a D::Target: TextSized,
{
#[inline]
fn text_size(self) -> TextSize {
self.deref().text_size()
}
}
```
This is "only" at the cost of a little extra impl complexity.
Co-authored-by: CAD97 <[email protected]>
0 commit comments