Repository: tokio-rs/tokio (language: rust)

Issue:
Please `impl Default for watch::Sender<T> where T: Default`
For types like `watch::Sender<Option<...>>`, it'd be convenient if `Sender` implemented `Default` if its contents did:

```rust
impl<T: Default> Default for Sender<T> {
    fn default() -> Self {
        Self::new(T::default())
    }
}
```

This would allow, for instance, using `.or_default()` in the `HashMap`/`DashMap` `Entry` API, rather than `.or_insert_with(|| watch::Sender::new(None))`.


Discussion / hints:
That sounds like a good idea.

Fix patch:
diff --git a/tokio/src/sync/watch.rs b/tokio/src/sync/watch.rs
index 80d479300db..5810c67de60 100644
--- a/tokio/src/sync/watch.rs
+++ b/tokio/src/sync/watch.rs
@@ -156,6 +156,12 @@ impl<T> Clone for Sender<T> {
     }
 }
 
+impl<T: Default> Default for Sender<T> {
+    fn default() -> Self {
+        Self::new(T::default())
+    }
+}
+
 /// Returns a reference to the inner value.
 ///
 /// Outstanding borrows hold a read lock on the inner value. This means that


Test patch: