From 0c66636d003979c3aecff36c9e03e87f34147a94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Sat, 2 Sep 2023 07:44:10 +0200 Subject: [PATCH] Use fmt::unwrap --- embassy-net/src/device.rs | 4 ++-- embassy-net/src/lib.rs | 14 +++++++------- embassy-net/src/tcp.rs | 4 ++-- embassy-sync/src/channel.rs | 2 +- embassy-sync/src/mutex.rs | 2 +- embassy-time/src/instant.rs | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/embassy-net/src/device.rs b/embassy-net/src/device.rs index d29ab8970..8c2b7d31a 100644 --- a/embassy-net/src/device.rs +++ b/embassy-net/src/device.rs @@ -22,13 +22,13 @@ where fn receive(&mut self, _timestamp: Instant) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)> { self.inner - .receive(self.cx.as_deref_mut().unwrap()) + .receive(unwrap!(self.cx.as_deref_mut())) .map(|(rx, tx)| (RxTokenAdapter(rx), TxTokenAdapter(tx))) } /// Construct a transmit token. fn transmit(&mut self, _timestamp: Instant) -> Option> { - self.inner.transmit(self.cx.as_deref_mut().unwrap()).map(TxTokenAdapter) + self.inner.transmit(unwrap!(self.cx.as_deref_mut())).map(TxTokenAdapter) } /// Get a description of device capabilities. diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs index 3a385fad6..c2575267c 100644 --- a/embassy-net/src/lib.rs +++ b/embassy-net/src/lib.rs @@ -616,7 +616,7 @@ impl Inner { } // Configure it - let socket = _s.sockets.get_mut::(self.dhcp_socket.unwrap()); + let socket = _s.sockets.get_mut::(unwrap!(self.dhcp_socket)); socket.set_ignore_naks(c.ignore_naks); socket.set_max_lease_duration(c.max_lease_duration.map(crate::time::duration_to_smoltcp)); socket.set_ports(c.server_port, c.client_port); @@ -656,12 +656,12 @@ impl Inner { debug!(" IP address: {:?}", config.address); debug!(" Default gateway: {:?}", config.gateway); - addrs.push(IpCidr::Ipv4(config.address)).unwrap(); + unwrap!(addrs.push(IpCidr::Ipv4(config.address)).ok()); gateway_v4 = config.gateway.into(); #[cfg(feature = "dns")] for s in &config.dns_servers { debug!(" DNS server: {:?}", s); - dns_servers.push(s.clone().into()).unwrap(); + unwrap!(dns_servers.push(s.clone().into()).ok()); } } else { info!("IPv4: DOWN"); @@ -673,12 +673,12 @@ impl Inner { debug!(" IP address: {:?}", config.address); debug!(" Default gateway: {:?}", config.gateway); - addrs.push(IpCidr::Ipv6(config.address)).unwrap(); + unwrap!(addrs.push(IpCidr::Ipv6(config.address)).ok()); gateway_v6 = config.gateway.into(); #[cfg(feature = "dns")] for s in &config.dns_servers { debug!(" DNS server: {:?}", s); - dns_servers.push(s.clone().into()).unwrap(); + unwrap!(dns_servers.push(s.clone().into()).ok()); } } else { info!("IPv6: DOWN"); @@ -690,13 +690,13 @@ impl Inner { // Apply gateways #[cfg(feature = "proto-ipv4")] if let Some(gateway) = gateway_v4 { - s.iface.routes_mut().add_default_ipv4_route(gateway).unwrap(); + unwrap!(s.iface.routes_mut().add_default_ipv4_route(gateway)); } else { s.iface.routes_mut().remove_default_ipv4_route(); } #[cfg(feature = "proto-ipv6")] if let Some(gateway) = gateway_v6 { - s.iface.routes_mut().add_default_ipv6_route(gateway).unwrap(); + unwrap!(s.iface.routes_mut().add_default_ipv6_route(gateway)); } else { s.iface.routes_mut().remove_default_ipv6_route(); } diff --git a/embassy-net/src/tcp.rs b/embassy-net/src/tcp.rs index c92ad2d2e..a12fd382a 100644 --- a/embassy-net/src/tcp.rs +++ b/embassy-net/src/tcp.rs @@ -440,7 +440,7 @@ impl<'d> TcpIo<'d> { Poll::Ready(Err(Error::ConnectionReset)) } } else { - Poll::Ready(match s.send(f.take().unwrap()) { + Poll::Ready(match s.send(unwrap!(f.take())) { // Connection reset. TODO: this can also be timeouts etc, investigate. Err(tcp::SendError::InvalidState) => Err(Error::ConnectionReset), Ok(r) => Ok(r), @@ -468,7 +468,7 @@ impl<'d> TcpIo<'d> { Poll::Ready(Err(Error::ConnectionReset)) } } else { - Poll::Ready(match s.recv(f.take().unwrap()) { + Poll::Ready(match s.recv(unwrap!(f.take())) { // Connection reset. TODO: this can also be timeouts etc, investigate. Err(tcp::RecvError::Finished) | Err(tcp::RecvError::InvalidState) => { Err(Error::ConnectionReset) diff --git a/embassy-sync/src/channel.rs b/embassy-sync/src/channel.rs index 62ea1307d..a512e0c41 100644 --- a/embassy-sync/src/channel.rs +++ b/embassy-sync/src/channel.rs @@ -471,7 +471,7 @@ where } fn lock(&self, f: impl FnOnce(&mut ChannelState) -> R) -> R { - self.inner.lock(|rc| f(&mut *rc.borrow_mut())) + self.inner.lock(|rc| f(&mut *unwrap!(rc.try_borrow_mut()))) } fn try_receive_with_context(&self, cx: Option<&mut Context<'_>>) -> Result { diff --git a/embassy-sync/src/mutex.rs b/embassy-sync/src/mutex.rs index fcf056d36..72459d660 100644 --- a/embassy-sync/src/mutex.rs +++ b/embassy-sync/src/mutex.rs @@ -149,7 +149,7 @@ where { fn drop(&mut self) { self.mutex.state.lock(|s| { - let mut s = s.borrow_mut(); + let mut s = unwrap!(s.try_borrow_mut()); s.locked = false; s.waker.wake(); }) diff --git a/embassy-time/src/instant.rs b/embassy-time/src/instant.rs index 44f226f62..5571cdd15 100644 --- a/embassy-time/src/instant.rs +++ b/embassy-time/src/instant.rs @@ -71,7 +71,7 @@ impl Instant { /// Panics on over/underflow. pub fn duration_since(&self, earlier: Instant) -> Duration { Duration { - ticks: self.ticks.checked_sub(earlier.ticks).unwrap(), + ticks: unwrap!(self.ticks.checked_sub(earlier.ticks)), } }