Use fmt::unwrap

This commit is contained in:
Dániel Buga 2023-09-02 07:44:10 +02:00
parent 8339423a2f
commit 0c66636d00
6 changed files with 14 additions and 14 deletions

View file

@ -22,13 +22,13 @@ where
fn receive(&mut self, _timestamp: Instant) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)> { fn receive(&mut self, _timestamp: Instant) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)> {
self.inner self.inner
.receive(self.cx.as_deref_mut().unwrap()) .receive(unwrap!(self.cx.as_deref_mut()))
.map(|(rx, tx)| (RxTokenAdapter(rx), TxTokenAdapter(tx))) .map(|(rx, tx)| (RxTokenAdapter(rx), TxTokenAdapter(tx)))
} }
/// Construct a transmit token. /// Construct a transmit token.
fn transmit(&mut self, _timestamp: Instant) -> Option<Self::TxToken<'_>> { fn transmit(&mut self, _timestamp: Instant) -> Option<Self::TxToken<'_>> {
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. /// Get a description of device capabilities.

View file

@ -616,7 +616,7 @@ impl<D: Driver + 'static> Inner<D> {
} }
// Configure it // Configure it
let socket = _s.sockets.get_mut::<dhcpv4::Socket>(self.dhcp_socket.unwrap()); let socket = _s.sockets.get_mut::<dhcpv4::Socket>(unwrap!(self.dhcp_socket));
socket.set_ignore_naks(c.ignore_naks); socket.set_ignore_naks(c.ignore_naks);
socket.set_max_lease_duration(c.max_lease_duration.map(crate::time::duration_to_smoltcp)); socket.set_max_lease_duration(c.max_lease_duration.map(crate::time::duration_to_smoltcp));
socket.set_ports(c.server_port, c.client_port); socket.set_ports(c.server_port, c.client_port);
@ -656,12 +656,12 @@ impl<D: Driver + 'static> Inner<D> {
debug!(" IP address: {:?}", config.address); debug!(" IP address: {:?}", config.address);
debug!(" Default gateway: {:?}", config.gateway); 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(); gateway_v4 = config.gateway.into();
#[cfg(feature = "dns")] #[cfg(feature = "dns")]
for s in &config.dns_servers { for s in &config.dns_servers {
debug!(" DNS server: {:?}", s); debug!(" DNS server: {:?}", s);
dns_servers.push(s.clone().into()).unwrap(); unwrap!(dns_servers.push(s.clone().into()).ok());
} }
} else { } else {
info!("IPv4: DOWN"); info!("IPv4: DOWN");
@ -673,12 +673,12 @@ impl<D: Driver + 'static> Inner<D> {
debug!(" IP address: {:?}", config.address); debug!(" IP address: {:?}", config.address);
debug!(" Default gateway: {:?}", config.gateway); 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(); gateway_v6 = config.gateway.into();
#[cfg(feature = "dns")] #[cfg(feature = "dns")]
for s in &config.dns_servers { for s in &config.dns_servers {
debug!(" DNS server: {:?}", s); debug!(" DNS server: {:?}", s);
dns_servers.push(s.clone().into()).unwrap(); unwrap!(dns_servers.push(s.clone().into()).ok());
} }
} else { } else {
info!("IPv6: DOWN"); info!("IPv6: DOWN");
@ -690,13 +690,13 @@ impl<D: Driver + 'static> Inner<D> {
// Apply gateways // Apply gateways
#[cfg(feature = "proto-ipv4")] #[cfg(feature = "proto-ipv4")]
if let Some(gateway) = gateway_v4 { 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 { } else {
s.iface.routes_mut().remove_default_ipv4_route(); s.iface.routes_mut().remove_default_ipv4_route();
} }
#[cfg(feature = "proto-ipv6")] #[cfg(feature = "proto-ipv6")]
if let Some(gateway) = gateway_v6 { 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 { } else {
s.iface.routes_mut().remove_default_ipv6_route(); s.iface.routes_mut().remove_default_ipv6_route();
} }

View file

@ -440,7 +440,7 @@ impl<'d> TcpIo<'d> {
Poll::Ready(Err(Error::ConnectionReset)) Poll::Ready(Err(Error::ConnectionReset))
} }
} else { } 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. // Connection reset. TODO: this can also be timeouts etc, investigate.
Err(tcp::SendError::InvalidState) => Err(Error::ConnectionReset), Err(tcp::SendError::InvalidState) => Err(Error::ConnectionReset),
Ok(r) => Ok(r), Ok(r) => Ok(r),
@ -468,7 +468,7 @@ impl<'d> TcpIo<'d> {
Poll::Ready(Err(Error::ConnectionReset)) Poll::Ready(Err(Error::ConnectionReset))
} }
} else { } 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. // Connection reset. TODO: this can also be timeouts etc, investigate.
Err(tcp::RecvError::Finished) | Err(tcp::RecvError::InvalidState) => { Err(tcp::RecvError::Finished) | Err(tcp::RecvError::InvalidState) => {
Err(Error::ConnectionReset) Err(Error::ConnectionReset)

View file

@ -471,7 +471,7 @@ where
} }
fn lock<R>(&self, f: impl FnOnce(&mut ChannelState<T, N>) -> R) -> R { fn lock<R>(&self, f: impl FnOnce(&mut ChannelState<T, N>) -> 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<T, TryReceiveError> { fn try_receive_with_context(&self, cx: Option<&mut Context<'_>>) -> Result<T, TryReceiveError> {

View file

@ -149,7 +149,7 @@ where
{ {
fn drop(&mut self) { fn drop(&mut self) {
self.mutex.state.lock(|s| { self.mutex.state.lock(|s| {
let mut s = s.borrow_mut(); let mut s = unwrap!(s.try_borrow_mut());
s.locked = false; s.locked = false;
s.waker.wake(); s.waker.wake();
}) })

View file

@ -71,7 +71,7 @@ impl Instant {
/// Panics on over/underflow. /// Panics on over/underflow.
pub fn duration_since(&self, earlier: Instant) -> Duration { pub fn duration_since(&self, earlier: Instant) -> Duration {
Duration { Duration {
ticks: self.ticks.checked_sub(earlier.ticks).unwrap(), ticks: unwrap!(self.ticks.checked_sub(earlier.ticks)),
} }
} }