The Default trait can be #[derive(..)]d only if the contents of the deriving type also implement Default. This means the trait gets easier to use the more it is implemented. However, I notice some types from std are missing implementations, although they have perfectly valid defaults (sometimes depending on generic params).
Mutex<T> and RWLock<T> could implement by new(_) (where T: Default)CondVar could simply implement by CondVar::new()
Duration could derive (to get a zero duration, Is there a technical reason for those omissions?
Some people have asked a similar question with Debug implementations, see “Missing Debug Implementations — #31869” which can also only be deriving under similar conditions as Default.
Unfortunately the corresponding PR “libcore: add Debug implementations to most missing types #32054” seems to suggest that some types were not Debug simply because no-one had written a Debug implementation for them. Some other types are kind of controversial about what the implementation should do and there is some fear about adding them in the standard library.
It reasonable to assume that at least some types are not Default for the same non-technical reasons.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With