-
-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(stylize)!: add Stylize impl for String (#466)
Although the `Stylize` trait is already implemented for `&str` which extends to `String`, it is not implemented for `String` itself. This commit adds an impl of Stylize that returns a Span<'static> for `String` so that code can call Stylize methods on temporary `String`s. E.g. the following now compiles instead of failing with a compile error about referencing a temporary value: let s = format!("hello {name}!", "world").red(); BREAKING CHANGE: This may break some code that expects to call Stylize methods on `String` values and then use the String value later. This will now fail to compile because the String is consumed by set_style instead of a slice being created and consumed. This can be fixed by cloning the `String`. E.g.: let s = String::from("hello world"); let line = Line::from(vec![s.red(), s.green()]); // fails to compile let line = Line::from(vec![s.clone().red(), s.green()]); // works
- Loading branch information
Showing
2 changed files
with
134 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters