Merge #23

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 <cad97@cad97.com>
tree: 96ff168e4e907053f5f1988289c7202570635bb9
  1. .github/
  2. src/
  3. tests/
  4. .gitignore
  5. bors.toml
  6. Cargo.toml
  7. LICENSE-APACHE
  8. LICENSE-MIT
  9. README.md
README.md

text_unit

Build Status Crates.io API reference

A library that provides newtype wrappers for u32 and (u32, u32) for use as text offsets.

See the docs for more.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.