From 938b29d418a9df2f93ee273a394f34adc99ea25d Mon Sep 17 00:00:00 2001 From: hozan23 Date: Sat, 18 Nov 2023 13:36:19 +0300 Subject: net: improve Conn API --- net/src/transports/udp.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'net/src/transports/udp.rs') diff --git a/net/src/transports/udp.rs b/net/src/transports/udp.rs index 27fb9ae..2050226 100644 --- a/net/src/transports/udp.rs +++ b/net/src/transports/udp.rs @@ -6,7 +6,7 @@ use smol::net::UdpSocket; use crate::{ connection::Connection, endpoint::{Addr, Endpoint, Port}, - Result, + Error, Result, }; /// UDP network connection implementations of the `Connection` trait. @@ -47,14 +47,12 @@ impl Connection for UdpConn { Ok(Endpoint::new_udp_addr(&self.inner.local_addr()?)) } - async fn recv(&self, buf: &mut [u8]) -> Result { - let size = self.inner.recv(buf).await?; - Ok(size) + async fn read(&self, buf: &mut [u8]) -> Result { + self.inner.recv(buf).await.map_err(Error::from) } - async fn send(&self, buf: &[u8]) -> Result { - let size = self.inner.send(buf).await?; - Ok(size) + async fn write(&self, buf: &[u8]) -> Result { + self.inner.send(buf).await.map_err(Error::from) } } -- cgit v1.2.3