feat(line)!: impl From<Cow<str>> for Line

BREAKING-CHANGES: `Line` now implements `From<Cow<str>`

As this adds an extra conversion, ambiguous inferred values may no
longer compile.

```rust
// given:
struct Foo { ... }
impl From<Foo> for String { ... }
impl From<Foo> for Cow<str> { ... }

let foo = Foo { ... };
let line = Line::from(foo); // now fails due to ambiguous type inference
// replace with
let line = Line::from(String::from(foo));
```

Fixes: https://github.com/ratatui/ratatui/issues/1367
This commit is contained in:
Josh McKinney 2024-09-15 20:29:04 -07:00
parent b88717b65f
commit bd5fa963ff
No known key found for this signature in database
GPG key ID: 722287396A903BC5
2 changed files with 26 additions and 2 deletions

View file

@ -65,6 +65,26 @@ This is a quick summary of the sections below:
- MSRV is now 1.63.0
- `List` no longer ignores empty strings
## v0.29.0 (Unreleased)
### `Line` now implements `From<Cow<str>` ([#1373])
[#1373]: https://github.com/ratatui/ratatui/pull/1373
As this adds an extra conversion, ambiguous inferred values may no longer compile.
```rust
// given:
struct Foo { ... }
impl From<Foo> for String { ... }
impl From<Foo> for Cow<str> { ... }
let foo = Foo { ... };
let line = Line::from(foo); // now fails due to now ambiguous inferred type
// replace with
let line = Line::from(String::from(foo));
```
## v0.28.0
### `Backend::size` returns `Size` instead of `Rect` ([#1254])
@ -136,8 +156,6 @@ This change simplifies the trait and makes it easier to implement.
### `Frame::size` is deprecated and renamed to `Frame::area`
[#1293]: https://github.com/ratatui/ratatui/pull/1293
`Frame::size` is renamed to `Frame::area` as it's the more correct name.
## [v0.27.0](https://github.com/ratatui/ratatui/releases/tag/v0.27.0)

View file

@ -515,6 +515,12 @@ impl<'a> From<&'a str> for Line<'a> {
}
}
impl<'a> From<Cow<'a, str>> for Line<'a> {
fn from(s: Cow<'a, str>) -> Self {
Self::raw(s)
}
}
impl<'a> From<Vec<Span<'a>>> for Line<'a> {
fn from(spans: Vec<Span<'a>>) -> Self {
Self {