-
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
Replace default_stat in std::path with a Default impl for libc::stat #9652
Conversation
@@ -392,6 +421,32 @@ pub mod types { | |||
st_blocks: blkcnt_t, | |||
st_pad5: [c_long, ..14], | |||
} | |||
impl Default for stat{ |
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.
space
This is going to conflict with my Path rewrite (#9655). |
As with a similar pull request recently, I feel like this suffers from the "making code less readable but more abstract" problem. It's really nice to call static methods on traits on type parameters, but it's not so nice to call static methods on traits directly. If I saw |
@alexcrichton The problem is the |
Oh I agree that there should be some method of getting a zero'd out stat struct, I just feel like isn't the best way of going about doing this. It's still the problem of where the first question you ask is "how do I get a stat struct?" and when the answer is "Default::default" you start questioning your morals. |
I think that the use of default to fill in missing fields is such a common pattern that it deserves a feature like the Default trait. But I agree that having to write Given that the usual answer to optional/named parameters is "use a struct," and given that there is special treatment for Default already (the "deriving" attribute) I also think both the Would that make it feel less immoral? In any case, here I'm just trying to make it possible to use |
This is working around a language issue that should be resolved at the "source" (making calling static methods on traits more "sensible", how ever that is done) rather than continually papering over the symptoms by defining standalone functions. |
I'm going to close this an #9637 because I don't think that this is the right way to go about doing this. The If it does end up being a large use case that external code needs to call |
[`zero_prefixed_literal`] Do not advise to use octal form if not possible fix rust-lang/rust-clippy#9651 changelog: [`zero_prefixed_literal`] Do not advise to use octal form if not possible
Instead of the internal
default_stat
function instd::path
, make thestat
structure implementDefault
and have the path code use that. Closes #9537. Alternative to #9637.