-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Merge ToStr and the Default format #9806
Comments
I think that this is tricky to do. Right now
That way nothing else really needs to implement One of the main things which I would like to avoid is a deriving-like format of the |
You are right, I was actually mixing issue #9807 into the proposal, and I shouldn't have - they are logically separate. Yes, indeed, if we ignore issue #9807, it makes more sense to merge |
I was talking to @alexcrichton on IRC, and he was ok with:
This would still require removing the |
This is in preparation for adding a `#[deriving(Format)]` and removing the `ToStr` trait, as discussed in rust-lang#9806.
This has been superseded by deriving(Show). cc rust-lang#9806
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()
andformat!("{}", foo)
; that is, the object needs to implement bothToStr
andDefault
.The proposal is to eliminate this duplication by eliminating
ToStr
and, instead, implementingto_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 implementingToStr
. 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.The text was updated successfully, but these errors were encountered: