Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Add on ColoredString #140

Open
hwittenborn opened this issue Jul 3, 2023 · 3 comments
Open

Implement Add on ColoredString #140

hwittenborn opened this issue Jul 3, 2023 · 3 comments
Labels
breaking Will need a major version bump

Comments

@hwittenborn
Copy link
Member

It would be nice to be able to add ColoredString instances together, so that something like "blue".blue() + "red".red() could be done. It would also be nice to add normal strings as well (i.e. "blue".blue() + "|" + "red".red()).

I'm not sure how this would work with #139 when mixing different formatter types though.

@hwittenborn
Copy link
Member Author

This will be added after #139 gets implemented, and the plan is to only allow it to function when T: impl Display. This is due to some limitations in Rust's trait system which wouldn't allow for multiple impl definitions (Rust wouldn't know what to call for Add if T implemented both Display and Debug).

To support multiple colored strings while still being able to get their sources, a Vec of some sort would have to be kept internally to keep track of all the strings, and it looks like the heapless crate would provide for that need just fine for no_std environments.

@hwittenborn hwittenborn added the breaking Will need a major version bump label Jul 5, 2023
@ToBinio
Copy link

ToBinio commented Jul 5, 2023

would this help with #115 ?

I am currently running into a similar issue to #115 and I believe this could be fixed by handling the whole text as a ColoredString

btw.
thanks @hwittenborn for bringing this project back to life ❤️

@ClementNerma
Copy link

I personally think this would cause more problems. There's a good reason String doesn't implement Add: aside from ergonomics, it hides an allocation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Will need a major version bump
Projects
None yet
Development

No branches or pull requests

3 participants