diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-08-27 21:46:44 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-08-27 21:46:44 +0200 |
commit | bfbe0bb3d87abdf7f2105c39366cb581d2382ecc (patch) | |
tree | 1a91879cf172fe515beebe7bd2415a67becbd6ce | |
parent | 3ba304d72aea68998423091b1d0c19f548a360e9 (diff) |
Remove match in favour of map()
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | src/client.rs | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/src/client.rs b/src/client.rs index 82781e8..ec8b42e 100644 --- a/src/client.rs +++ b/src/client.rs @@ -32,22 +32,17 @@ pub struct FlicClient { impl FlicClient { pub async fn new(conn: &str) -> Result<FlicClient> { - match TcpStream::connect(conn).await { - - Ok(stream) => { - let (reader, writer) = stream.into_split(); - Ok(FlicClient{ - reader: Mutex::new(reader), - writer: Mutex::new(writer), - is_running: Mutex::new(true), - command_mapper: Mutex::new(CommandToByteMapper::new()), - event_mapper: Mutex::new(ByteToEventMapper::new()), - map: Mutex::new(vec![]), - }) - } - Err(err) => Err(err) - } - + TcpSTream::connect(con) + .await + .map(|s| s.into_split()) + .map(|(reader, writer)| FlicClient { + reader: Mutex::new(reader), + writer: Mutex::new(writer), + is_running: Mutex::new(true), + command_mapper: Mutex::new(CommandToByteMapper::new()), + event_mapper: Mutex::new(ByteToEventMapper::new()), + map: Mutex::new(vec![]), + }) } pub async fn register_event_handler(self, event: EventClosureMutex) -> Self { self.map.lock().await.push(event); |