fix: nightly fmt

This commit is contained in:
skkeye 2025-02-09 02:11:15 -05:00 committed by Ulf Lilleengen
parent 38b5f8bd0a
commit bdb1b81213
4 changed files with 34 additions and 32 deletions

View File

@ -252,24 +252,24 @@ impl Drop for IcmpSocket<'_> {
pub mod ping { pub mod ping {
//! Ping utilities. //! Ping utilities.
//! //!
//! This module allows for an easy ICMP Echo message interface used to //! This module allows for an easy ICMP Echo message interface used to
//! ping devices with an [ICMP Socket](IcmpSocket). //! ping devices with an [ICMP Socket](IcmpSocket).
//! //!
//! ## Usage //! ## Usage
//! //!
//! ``` //! ```
//! use core::net::Ipv4Addr; //! use core::net::Ipv4Addr;
//! use core::str::FromStr; //! use core::str::FromStr;
//! //!
//! use embassy_net::icmp::ping::{PingManager, PingParams}; //! use embassy_net::icmp::ping::{PingManager, PingParams};
//! use embassy_net::icmp::PacketMetadata; //! use embassy_net::icmp::PacketMetadata;
//! //!
//! let mut rx_buffer = [0; 256]; //! let mut rx_buffer = [0; 256];
//! let mut tx_buffer = [0; 256]; //! let mut tx_buffer = [0; 256];
//! let mut rx_meta = [PacketMetadata::EMPTY]; //! let mut rx_meta = [PacketMetadata::EMPTY];
//! let mut tx_meta = [PacketMetadata::EMPTY]; //! let mut tx_meta = [PacketMetadata::EMPTY];
//! //!
//! let mut ping_manager = PingManager::new(stack, &mut rx_meta, &mut rx_buffer, &mut tx_meta, &mut tx_buffer); //! let mut ping_manager = PingManager::new(stack, &mut rx_meta, &mut rx_buffer, &mut tx_meta, &mut tx_buffer);
//! let addr = "192.168.8.1"; //! let addr = "192.168.8.1";
//! let mut ping_params = PingParams::new(Ipv4Addr::from_str(addr).unwrap()); //! let mut ping_params = PingParams::new(Ipv4Addr::from_str(addr).unwrap());
@ -280,16 +280,18 @@ pub mod ping {
//! }; //! };
//! ``` //! ```
use super::*;
use core::net::{IpAddr, Ipv6Addr}; use core::net::{IpAddr, Ipv6Addr};
use embassy_time::{Duration, Instant, Timer, WithTimeout}; use embassy_time::{Duration, Instant, Timer, WithTimeout};
use super::*;
/// Error returned by [`ping()`](PingManager::ping). /// Error returned by [`ping()`](PingManager::ping).
#[derive(PartialEq, Eq, Clone, Copy, Debug)] #[derive(PartialEq, Eq, Clone, Copy, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum PingError { pub enum PingError {
/// The target did not respond. /// The target did not respond.
/// ///
/// The packet was sent but the Reply packet has not been recieved /// The packet was sent but the Reply packet has not been recieved
/// in the timeout set by [`set_timeout()`](PingParams::set_timeout). /// in the timeout set by [`set_timeout()`](PingParams::set_timeout).
DestinationHostUnreachable, DestinationHostUnreachable,
@ -339,7 +341,7 @@ pub mod ping {
impl<'d> PingManager<'d> { impl<'d> PingManager<'d> {
/// Creates a new instance of [`PingManager`] with a [`Stack`] instance /// Creates a new instance of [`PingManager`] with a [`Stack`] instance
/// and the buffers used for RX and TX. /// and the buffers used for RX and TX.
/// ///
/// **note**: This does not yet creates the ICMP socket. /// **note**: This does not yet creates the ICMP socket.
pub fn new( pub fn new(
stack: Stack<'d>, stack: Stack<'d>,
@ -387,7 +389,7 @@ pub mod ping {
// Make sure each ping takes at least 1 second to respect standards // Make sure each ping takes at least 1 second to respect standards
let rate_limit_start = Instant::now(); let rate_limit_start = Instant::now();
// make a single ping // make a single ping
// - shorts out errors // - shorts out errors
// - select the ip version // - select the ip version
let ping_duration = match params.target().unwrap() { let ping_duration = match params.target().unwrap() {
@ -564,7 +566,6 @@ pub mod ping {
} }
} }
/// Parameters for configuring the ping operation. /// Parameters for configuring the ping operation.
/// ///
/// This struct provides various configuration options for performing ICMP ping operations, /// This struct provides various configuration options for performing ICMP ping operations,
@ -653,7 +654,7 @@ pub mod ping {
} }
/// Sets the hop limit that will be used by the socket with [`set_hop_limit()`](IcmpSocket::set_hop_limit). /// Sets the hop limit that will be used by the socket with [`set_hop_limit()`](IcmpSocket::set_hop_limit).
/// ///
/// **Note**: A hop limit of [`Some(0)`](Some()) is equivalent to a hop limit of [`None`]. /// **Note**: A hop limit of [`Some(0)`](Some()) is equivalent to a hop limit of [`None`].
pub fn set_hop_limit(&mut self, hop_limit: Option<u8>) -> &mut Self { pub fn set_hop_limit(&mut self, hop_limit: Option<u8>) -> &mut Self {
let mut hop_limit = hop_limit; let mut hop_limit = hop_limit;
@ -669,9 +670,9 @@ pub mod ping {
self.hop_limit self.hop_limit
} }
/// Sets the count used for specifying the number of pings done on one /// Sets the count used for specifying the number of pings done on one
/// [`ping()`](PingManager::ping) call. /// [`ping()`](PingManager::ping) call.
/// ///
/// **Note**: A count of 0 will be set as 1. /// **Note**: A count of 0 will be set as 1.
pub fn set_count(&mut self, count: u16) -> &mut Self { pub fn set_count(&mut self, count: u16) -> &mut Self {
let mut count = count; let mut count = count;
@ -682,7 +683,7 @@ pub mod ping {
self self
} }
/// Retrieve the count used for specifying the number of pings done on one /// Retrieve the count used for specifying the number of pings done on one
/// [`ping()`](PingManager::ping) call. /// [`ping()`](PingManager::ping) call.
pub fn count(&self) -> u16 { pub fn count(&self) -> u16 {
self.count self.count

View File

@ -15,6 +15,8 @@ pub(crate) mod fmt;
#[cfg(feature = "dns")] #[cfg(feature = "dns")]
pub mod dns; pub mod dns;
mod driver_util; mod driver_util;
#[cfg(feature = "icmp")]
pub mod icmp;
#[cfg(feature = "raw")] #[cfg(feature = "raw")]
pub mod raw; pub mod raw;
#[cfg(feature = "tcp")] #[cfg(feature = "tcp")]
@ -22,8 +24,6 @@ pub mod tcp;
mod time; mod time;
#[cfg(feature = "udp")] #[cfg(feature = "udp")]
pub mod udp; pub mod udp;
#[cfg(feature = "icmp")]
pub mod icmp;
use core::cell::RefCell; use core::cell::RefCell;
use core::future::{poll_fn, Future}; use core::future::{poll_fn, Future};

View File

@ -1,5 +1,5 @@
//! This example implements an echo (ping) with an ICMP Socket and using defmt to report the results. //! This example implements an echo (ping) with an ICMP Socket and using defmt to report the results.
//! //!
//! Although there is a better way to execute pings using the child module ping of the icmp module, //! Although there is a better way to execute pings using the child module ping of the icmp module,
//! this example allows for other icmp messages like `Destination unreachable` to be sent aswell. //! this example allows for other icmp messages like `Destination unreachable` to be sent aswell.
//! //!
@ -106,16 +106,12 @@ async fn main(spawner: Spawner) {
// Send the packet and store the starting instant to mesure latency later // Send the packet and store the starting instant to mesure latency later
let start = socket let start = socket
.send_to_with( .send_to_with(icmp_repr.buffer_len(), cfg.gateway.unwrap(), |buf| {
icmp_repr.buffer_len(), // Create and populate the packet buffer allocated by `send_to_with`
cfg.gateway.unwrap(), let mut icmp_packet = Icmpv4Packet::new_unchecked(buf);
|buf| { icmp_repr.emit(&mut icmp_packet, &ChecksumCapabilities::default());
// Create and populate the packet buffer allocated by `send_to_with` Instant::now() // Return the instant where the packet was sent
let mut icmp_packet = Icmpv4Packet::new_unchecked(buf); })
icmp_repr.emit(&mut icmp_packet, &ChecksumCapabilities::default());
Instant::now() // Return the instant where the packet was sent
},
)
.await .await
.unwrap(); .unwrap();
@ -123,7 +119,12 @@ async fn main(spawner: Spawner) {
socket socket
.recv_with(|(buf, addr)| { .recv_with(|(buf, addr)| {
let packet = Icmpv4Packet::new_checked(buf).unwrap(); let packet = Icmpv4Packet::new_checked(buf).unwrap();
info!("Recieved {:?} from {} in {}ms", packet.data(), addr, start.elapsed().as_millis()); info!(
"Recieved {:?} from {} in {}ms",
packet.data(),
addr,
start.elapsed().as_millis()
);
}) })
.await .await
.unwrap(); .unwrap();

View File

@ -100,7 +100,7 @@ async fn main(spawner: Spawner) {
// Create the ping manager instance // Create the ping manager instance
let mut ping_manager = PingManager::new(stack, &mut rx_meta, &mut rx_buffer, &mut tx_meta, &mut tx_buffer); let mut ping_manager = PingManager::new(stack, &mut rx_meta, &mut rx_buffer, &mut tx_meta, &mut tx_buffer);
let addr = "192.168.8.1"; // Address to ping to let addr = "192.168.8.1"; // Address to ping to
// Create the PingParams with the target address // Create the PingParams with the target address
let mut ping_params = PingParams::new(Ipv4Addr::from_str(addr).unwrap()); let mut ping_params = PingParams::new(Ipv4Addr::from_str(addr).unwrap());
// (optional) Set custom properties of the ping // (optional) Set custom properties of the ping
ping_params.set_payload(b"Hello, Ping!"); // custom payload ping_params.set_payload(b"Hello, Ping!"); // custom payload
@ -118,7 +118,7 @@ async fn main(spawner: Spawner) {
Ok(time) => { Ok(time) => {
info!("{} is online\n- latency: {}ms\n", ip_addr, time.as_millis()); info!("{} is online\n- latency: {}ms\n", ip_addr, time.as_millis());
total_online_hosts += 1; total_online_hosts += 1;
}, }
_ => continue, _ => continue,
} }
} }