Removed unnecessary generics from structs

This commit is contained in:
Jonah Dahlquist 2019-08-01 08:38:42 -05:00
commit e8e44413d3

View file

@ -107,13 +107,13 @@ pub enum ArpResponses {
pub struct UninitializedSocket(Socket); pub struct UninitializedSocket(Socket);
pub struct UdpSocket(Socket); pub struct UdpSocket(Socket);
pub struct W5500<'a, ChipSelectError, ChipSelect: OutputPin<Error = ChipSelectError>> { pub struct W5500<'a, ChipSelect: OutputPin> {
chip_select: &'a mut ChipSelect, chip_select: &'a mut ChipSelect,
sockets: u8, // each bit represents whether the corresponding socket is available for take sockets: u8, // each bit represents whether the corresponding socket is available for take
} }
impl<'b, 'a: 'b, ChipSelectError, ChipSelect: OutputPin<Error = ChipSelectError>> impl<'b, 'a: 'b, ChipSelectError, ChipSelect: OutputPin<Error = ChipSelectError>>
W5500<'a, ChipSelectError, ChipSelect> W5500<'a, ChipSelect>
{ {
fn new(chip_select: &'a mut ChipSelect) -> Self { fn new(chip_select: &'a mut ChipSelect) -> Self {
W5500 { W5500 {
@ -122,14 +122,14 @@ impl<'b, 'a: 'b, ChipSelectError, ChipSelect: OutputPin<Error = ChipSelectError>
} }
} }
pub fn with_initialisation<'c, E, Spi: FullDuplex<u8, Error = E>>( pub fn with_initialisation<'c, SpiError, Spi: FullDuplex<u8, Error = SpiError>>(
chip_select: &'a mut ChipSelect, chip_select: &'a mut ChipSelect,
spi: &'c mut Spi, spi: &'c mut Spi,
wol: OnWakeOnLan, wol: OnWakeOnLan,
ping: OnPingRequest, ping: OnPingRequest,
mode: ConnectionType, mode: ConnectionType,
arp: ArpResponses, arp: ArpResponses,
) -> Result<Self, TransferError<E, ChipSelectError>> { ) -> Result<Self, TransferError<SpiError, ChipSelectError>> {
let mut w5500 = Self::new(chip_select); let mut w5500 = Self::new(chip_select);
{ {
let mut w5500_active = w5500.activate(spi)?; let mut w5500_active = w5500.activate(spi)?;
@ -151,33 +151,26 @@ impl<'b, 'a: 'b, ChipSelectError, ChipSelect: OutputPin<Error = ChipSelectError>
} }
} }
pub fn activate<'c, E, Spi: FullDuplex<u8, Error = E>>( pub fn activate<'c, SpiError, Spi: FullDuplex<u8, Error = SpiError>>(
&'b mut self, &'b mut self,
spi: &'c mut Spi, spi: &'c mut Spi,
) -> Result< ) -> Result<ActiveW5500<'b, 'a, 'c, ChipSelect, Spi>, TransferError<SpiError, ChipSelectError>>
ActiveW5500<'b, 'a, 'c, E, ChipSelectError, ChipSelect, Spi>, {
TransferError<E, ChipSelectError>,
> {
Ok(ActiveW5500(self, spi)) Ok(ActiveW5500(self, spi))
} }
} }
pub struct ActiveW5500< pub struct ActiveW5500<'a, 'b: 'a, 'c, ChipSelect: OutputPin, Spi: FullDuplex<u8>>(
'a, &'a mut W5500<'b, ChipSelect>,
'b: 'a, &'c mut Spi,
'c, );
SpiError,
ChipSelectError,
ChipSelect: OutputPin<Error = ChipSelectError>,
Spi: FullDuplex<u8, Error = SpiError>,
>(&'a mut W5500<'b, ChipSelectError, ChipSelect>, &'c mut Spi);
impl< impl<
SpiError,
ChipSelectError, ChipSelectError,
ChipSelect: OutputPin<Error = ChipSelectError>, ChipSelect: OutputPin<Error = ChipSelectError>,
SpiError,
Spi: FullDuplex<u8, Error = SpiError>, Spi: FullDuplex<u8, Error = SpiError>,
> ActiveW5500<'_, '_, '_, SpiError, ChipSelectError, ChipSelect, Spi> > ActiveW5500<'_, '_, '_, ChipSelect, Spi>
{ {
pub fn take_socket(&mut self, socket: Socket) -> Option<UninitializedSocket> { pub fn take_socket(&mut self, socket: Socket) -> Option<UninitializedSocket> {
self.0.take_socket(socket) self.0.take_socket(socket)
@ -407,13 +400,13 @@ pub trait IntoUdpSocket<SpiError> {
} }
impl< impl<
SpiError,
ChipSelectError, ChipSelectError,
ChipSelect: OutputPin<Error = ChipSelectError>, ChipSelect: OutputPin<Error = ChipSelectError>,
SpiError,
Spi: FullDuplex<u8, Error = SpiError>, Spi: FullDuplex<u8, Error = SpiError>,
> IntoUdpSocket<UninitializedSocket> > IntoUdpSocket<UninitializedSocket>
for ( for (
&mut ActiveW5500<'_, '_, '_, SpiError, ChipSelectError, ChipSelect, Spi>, &mut ActiveW5500<'_, '_, '_, ChipSelect, Spi>,
UninitializedSocket, UninitializedSocket,
) )
{ {
@ -456,10 +449,7 @@ impl<
ChipSelect: OutputPin<Error = ChipSelectError>, ChipSelect: OutputPin<Error = ChipSelectError>,
Spi: FullDuplex<u8, Error = SpiError>, Spi: FullDuplex<u8, Error = SpiError>,
> Udp<SpiError, ChipSelectError> > Udp<SpiError, ChipSelectError>
for ( for (&mut ActiveW5500<'_, '_, '_, ChipSelect, Spi>, &UdpSocket)
&mut ActiveW5500<'_, '_, '_, SpiError, ChipSelectError, ChipSelect, Spi>,
&UdpSocket,
)
{ {
fn receive( fn receive(
&mut self, &mut self,