Ran formatting

This commit is contained in:
Jonah Dahlquist 2019-09-05 20:39:47 -05:00 committed by Jonah Dahlquist
commit 95ca1be001
5 changed files with 64 additions and 22 deletions

View file

@ -1,9 +1,9 @@
use crate::socket::Socket;
use crate::w5500::ForeignSocketError;
use crate::udp::UdpSocket;
use crate::w5500::W5500;
use crate::bus::ActiveBus;
use crate::network::Network;
use crate::socket::Socket;
use crate::udp::UdpSocket;
use crate::w5500::ForeignSocketError;
use crate::w5500::W5500;
pub struct InactiveUdpSocket<'a, SocketImpl: Socket> {
socket: &'a mut SocketImpl,
@ -14,10 +14,18 @@ impl<'a, SocketImpl: Socket> InactiveUdpSocket<'a, SocketImpl> {
InactiveUdpSocket { socket }
}
pub fn activate<SpiBus: ActiveBus, NetworkImpl: Network>(self, w5500: W5500<SpiBus, NetworkImpl>) -> Result<UdpSocket<'a, SpiBus, NetworkImpl, SocketImpl>, ForeignSocketError> {
pub fn activate<SpiBus: ActiveBus, NetworkImpl: Network>(
self,
w5500: W5500<SpiBus, NetworkImpl>,
) -> Result<UdpSocket<'a, SpiBus, NetworkImpl, SocketImpl>, ForeignSocketError> {
let (bus, network, sockets) = w5500.release();
if self.socket.is_owned_by(&sockets) {
Ok(UdpSocket { bus, network, sockets, socket: self.socket })
Ok(UdpSocket {
bus,
network,
sockets,
socket: self.socket,
})
} else {
Err(ForeignSocketError {})
}

View file

@ -2,10 +2,10 @@ mod inactive_udp_socket;
use crate::bus::ActiveBus;
use crate::network::Network;
use crate::socket::Socket;
use crate::w5500::W5500;
use crate::udp::inactive_udp_socket::InactiveUdpSocket;
use crate::socket::OwnedSockets;
use crate::socket::Socket;
use crate::udp::inactive_udp_socket::InactiveUdpSocket;
use crate::w5500::W5500;
use register::socketn;
pub struct UdpSocket<'a, SpiBus: ActiveBus, NetworkImpl: Network, SocketImpl: Socket> {
@ -16,16 +16,37 @@ pub struct UdpSocket<'a, SpiBus: ActiveBus, NetworkImpl: Network, SocketImpl: So
socket: &'a mut SocketImpl,
}
impl<'a, SpiBus: ActiveBus, NetworkImpl: Network, SocketImpl: Socket> UdpSocket<'a, SpiBus, NetworkImpl, SocketImpl> {
pub fn new(port: u16, mut bus: SpiBus, network: NetworkImpl, sockets: OwnedSockets, socket: &'a mut SocketImpl) -> Result<Self, SpiBus::Error> {
impl<'a, SpiBus: ActiveBus, NetworkImpl: Network, SocketImpl: Socket>
UdpSocket<'a, SpiBus, NetworkImpl, SocketImpl>
{
pub fn new(
port: u16,
mut bus: SpiBus,
network: NetworkImpl,
sockets: OwnedSockets,
socket: &'a mut SocketImpl,
) -> Result<Self, SpiBus::Error> {
socket.reset_interrupt(&mut bus, socketn::Interrupt::SendOk)?;
socket.set_source_port(&mut bus, port)?;
socket.set_mode(&mut bus, socketn::Protocol::Udp)?;
Ok(UdpSocket { bus, network, sockets, socket })
Ok(UdpSocket {
bus,
network,
sockets,
socket,
})
}
pub fn deactivate(self) -> (InactiveUdpSocket<'a, SocketImpl>, W5500<SpiBus, NetworkImpl>) {
(InactiveUdpSocket::new(self.socket), W5500::new(self.bus, self.network, self.sockets))
pub fn deactivate(
self,
) -> (
InactiveUdpSocket<'a, SocketImpl>,
W5500<SpiBus, NetworkImpl>,
) {
(
InactiveUdpSocket::new(self.socket),
W5500::new(self.bus, self.network, self.sockets),
)
}
}