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

[feature] add Join trait #132

Open
after-ephemera opened this issue May 11, 2023 · 5 comments
Open

[feature] add Join trait #132

after-ephemera opened this issue May 11, 2023 · 5 comments

Comments

@after-ephemera
Copy link

It would be nice it ColoredString implemented Join so you can join slices of ColoredStrings.

@hwittenborn
Copy link
Member

Thanks for the issie @after-ephemera! I looked at the documentation for Join and you can only implement it on Rust Nightly right now, and I'd likewise probably end up holding off on implementing it.

Would the Add trait be acceptable for you? Then you could do stuff like ColoredString + &ColoredString, which I feel like would be a more common use case as well.

What do you think?

@after-ephemera
Copy link
Author

Yeah I think Add would be absolutely sufficient for this kind of use case.

@asibahi
Copy link

asibahi commented Aug 5, 2023

Hello I came into here looking for a join method as well. I have a vector of ColoredString which I need to put into one giant ColoredString. Currently I have it set up like this

    let mut buffer = String::new();
    for part in colored_strings {
        write!(buffer, "{part}")?;
    }
    buffer

and I am hoping to return a ColoredString instead of a String.

@kurtlawrence
Copy link
Collaborator

kurtlawrence commented Aug 6, 2023

It might be worth implementing FromIterator

https://doc.rust-lang.org/std/iter/trait.FromIterator.html

@Nodd
Copy link

Nodd commented Sep 28, 2024

I have the same problem as @asibahi. I'm learning Rust and I'm still struggling to find an alternative.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants