tokio-rs / tokio

A runtime for writing reliable asynchronous applications with Rust. Provides I/O, networking, scheduling, timers, ...
https://tokio.rs
MIT License
25.44k stars 2.3k forks source link

Please `impl Default for watch::Sender<T> where T: Default` #6623

Closed joshtriplett closed 4 weeks ago

joshtriplett commented 4 weeks ago

For types like watch::Sender<Option<...>>, it'd be convenient if Sender implemented Default if its contents did:

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)).

Darksonn commented 4 weeks ago

That sounds like a good idea.