Why is Default not implemented for Mutex, RWLock, CondVar, Duration?

The Default attribute can be #[derive(..)] d only if the contents of the output type also implement Default . This means that this feature becomes easier to use the more it is implemented. However, I notice that some types from std do not have implementations, although they have completely acceptable default values ​​(sometimes depending on general parameters).

  • Mutex<T> and RWLock<T> can be implemented using new(_) ( where T: Default )
  • CondVar can simply implement CondVar::new()
  • Duration can get (to get zero duration , which is a reasonable default )

Is there a technical reason for these omissions?

+5
source share
1 answer

Some people asked a similar question with Debug implementations, see "Lack of debugging implementations - # 31869" , which can also be obtained under similar Default conditions.

Unfortunately, the corresponding PR " libcore: add debugging options for most missing types # 32054 " seems to suggest that some types were not Debug simply because no one wrote a Debug implementation for them. Some other types are pretty controversial as to what the implementation should do, and there are some concerns about adding them to the standard library.

It is reasonable to assume that at least some types are not Default for the same non-technical reasons.

+1
source

Source: https://habr.com/ru/post/1246632/


All Articles