From 0185724e6e45251ac66e64ed107aac05f2bba1f0 Mon Sep 17 00:00:00 2001 From: Michael Watzko Date: Thu, 1 Aug 2019 16:28:25 +0200 Subject: [PATCH] Replace generic errors of Udp into a associative type --- src/lib.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index cf9f6d7..2d300f2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -425,26 +425,31 @@ impl> IntoUdpSocket { +pub trait Udp { + type Error; + fn receive( &mut self, target_buffer: &mut [u8], - ) -> Result, TransferError>; + ) -> Result, Self::Error>; + fn blocking_send( &mut self, host: &IpAddress, host_port: u16, data: &[u8], - ) -> Result<(), TransferError>; + ) -> Result<(), Self::Error>; } -impl> Udp +impl> Udp for (&mut ActiveW5500<'_, '_, '_, ChipSelect, Spi>, &UdpSocket) { + type Error = TransferError; + fn receive( &mut self, destination: &mut [u8], - ) -> Result, TransferError> { + ) -> Result, Self::Error> { let (w5500, UdpSocket(socket)) = self; if w5500.read_u8(socket.at(SocketRegister::InterruptMask))? & 0x04 == 0 { @@ -500,7 +505,7 @@ impl> Udp Result<(), TransferError> { + ) -> Result<(), Self::Error> { let (w5500, UdpSocket(socket)) = self; {