Skip to content

Have std::string::ToString for X automatically provide std::convert::From<X> for String #2209

@mqudsi

Description

@mqudsi

Is there a good reason the following can't be done?

impl<T> std::convert::From<T> for std::string::String where T: std::string::ToString {
    fn from(t: T) -> Self {
        t.to_string()
    }

The only thing I can think of is if the value of T converted to String has a different meaning of the value of T.display() (as that's where a lot of the ToString implementations are coming from) such that you might want different behavior there.

Being able to do something like s: String = 42.into() anywhere would be nice.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-apiRelevant to the library API team, which will review and decide on the RFC.breaking-changeThe RFC proposes a breaking change.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions