-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Add a Default trait. #8438
Add a Default trait. #8438
Conversation
This is like |
@@ -148,7 +148,7 @@ pub mod clone; | |||
pub mod io; | |||
pub mod hash; | |||
pub mod container; | |||
|
|||
pub mod default; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this file ended up getting added.
We could probably just transition everything using I think that |
This PR doesn't offer any justification for this feature, link to relevant issues that it solves, doesn't convert any code to use it. I'm getting a little wary of all the new minor features being introduced just because we can. Every thing that goes in introduces new maintenance and cognitive burden, and the closer those features are to the core of the language (as this is) the more justification is required. Let's consider whether we really need both |
I stand corrected. There is a linked issue. |
What specific types, that don't already implement |
@brson: The I've often needed a way to construct new empty containers in generic code, and a I definitely think it would be a lesser evil to support |
Ugh I screwed that commit up major, but I'm going to just start work on TWiR rather than fixing it. |
@brson anything that has a static method |
Ok, I'm convinced. Thanks. |
Should Hmm, one note though is that then people would have to |
The reason I don't really like calling it |
@thestinger @brson @bblum it actually isn't a problem at all, it could be named trait Newable {
pub fn new() -> Self;
}
struct Foo;
impl Newable for Foo {
pub fn new() -> Foo { Foo }
}
impl Foo {
pub fn new(x: uint) -> Foo { Foo }
}
fn main() {
printfln!("%?, %?", Newable::new::<Foo>(), Foo::new(42));
} |
That relies on the assumption that we will never do trait-based resolution for |
@pcwalton mind chiming in on that? |
We should just be able to import static methods. I am very opposed to trait resolution on |
@cmr: needs to be updated for the visibility modifier changes |
@thestinger thanks, fixed. |
@cmr Needs a rebase. |
Test failure is legitimate. This PR removed Zero impls for strings, and the failed test tests precisely that. |
No description provided.