Skip to content

Merge ToStr and the Default format #9806

Closed
@orenbenkiki

Description

Now that the Default trait has been added for handling {} format, there are two ways to define how to convert an object to a string: foo.to_str() and format!("{}", foo); that is, the object needs to implement both ToStr and Default.

The proposal is to eliminate this duplication by eliminating ToStr and, instead, implementing to_str() by internally invoking the formatting function. This of course would be a major breaking change to existing code.

An alternative would be to provide a "default implementation" for the Default trait for anything implementing ToStr. This would be a backward-compatible change but would require extending the type system to allow for allowing default implementation of traits (if the type implements some other traits) with the ability to override the implementation for specific types.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions