Closed mahor1221 closed 11 months ago
Why's this needed @mahor1221? Running String::from("blue").blue()
locally works just fine, is there some other use case you're needing?
I frequently use the into()
method in my codebase as it makes refactoring easier and I want to maintain consistency and avoid using any alternative methods. For example:
fn paint(vec: Vec<String>) -> ColoredString {
vec
.iter()
.map(|_| todo!())
.collect::<String>()
.into()
}
In the code above, if I change ColoredString
to another type, such as NewTypeFromColoredString
, and this new type implements the From
or Into
trait, the code should work without requiring additional changes.
Is there anything blocking this? This functionality would be nice and I'm very surprised that this has not happened yet. From<&str> is not good enough since it requires both an additional copy and a new heap allocation where From
Thanks @mahor1221!
Complements
impl<'a> From<&'a str> for ColoredString
.