From 9d9f21405b46289e329e5c50fb915139680e18d3 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Sat, 5 Dec 2020 11:31:03 +0100 Subject: [PATCH] simplify singleton channel we can directly use Option without wrapping it --- src/channel.rs | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/src/channel.rs b/src/channel.rs index 4d09190..6f7daf4 100644 --- a/src/channel.rs +++ b/src/channel.rs @@ -55,26 +55,9 @@ impl ChannelData for HashSet { Singleton Channel <<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> \*/ -pub struct SingletonChannel(Option); - -impl Default for SingletonChannel { - fn default() -> Self { - SingletonChannel(None) - } -} - -impl IntoIterator for SingletonChannel { - type Item = T; - type IntoIter = std::iter::Once; - - fn into_iter(mut self) -> Self::IntoIter { - std::iter::once(self.0.take().unwrap()) - } -} - -impl ChannelData for SingletonChannel { +impl ChannelData for Option { fn channel_insert(&mut self, x: T) { - self.0 = Some(x); + *self = Some(x); } } @@ -184,11 +167,11 @@ pub fn set_channel() -> (ChannelSender>, ChannelReceive channel::>() } -pub fn queue_channel() -> (ChannelSender>, ChannelReceiver>) { +pub fn queue_channel() -> (ChannelSender>, ChannelReceiver>) { channel::>() } -pub fn singleton_channel() -> (ChannelSender>, ChannelReceiver>) { - channel::>() +pub fn singleton_channel() -> (ChannelSender>, ChannelReceiver>) { + channel::>() }