From 343db2a460ed277c5bcee01c80bdcc1a20c85b0b Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Tue, 3 Sep 2024 12:49:10 +0300 Subject: [PATCH] Deprecate more --- README.md | 2 +- src/lib.rs | 39 ++++++++++----------------------------- 2 files changed, 11 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 984b07b..b6b4428 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A crate to return the maximum transmission unit (MTU) of the local network inter ## Usage -The main function exported by this crate is +This crate exports a single function ```rust pub fn interface_and_mtu(remote: &SocketAddr) -> Result<(String, usize), Error> diff --git a/src/lib.rs b/src/lib.rs index 25c0d2a..d968133 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -74,12 +74,6 @@ pub fn interface_and_mtu(remote: &SocketAddr) -> Result<(String, usize), Error> res } -#[doc(hidden)] -#[deprecated(since = "0.1.2", note = "Use `interface_mtu()` instead")] -pub fn get_interface_mtu(remote: &SocketAddr) -> Result { - interface_mtu(remote) -} - #[cfg(any(target_os = "macos", target_os = "linux"))] fn interface_and_mtu_linux_macos(socket: &UdpSocket) -> Result<(String, usize), Error> { use std::ffi::{c_int, CStr}; @@ -269,31 +263,18 @@ fn interface_and_mtu_windows(socket: &UdpSocket) -> Result<(String, usize), Erro res } -/// Return the maximum transmission unit (MTU) of the local network interface towards the -/// destination [`SocketAddr`] given in `remote`. -/// -/// The returned MTU may exceed the maximum IP packet size of 65,535 bytes on some -/// platforms for some remote destinations. (For example, loopback destinations on -/// Windows.) -/// -/// This function is a convenience wrapper around [`interface_and_mtu`] that only returns the -/// MTU. It is provided for compatibility with version 0.1 of the `mtu` crate. -/// -/// # Examples -/// -/// ``` -/// let saddr = "127.0.0.1:443".parse().unwrap(); -/// let mtu = mtu::interface_mtu(&saddr).unwrap(); -/// println!("MTU towards {saddr:?} is {mtu}"); -/// ``` -/// -/// # Errors -/// -/// This function returns an error if the local interface MTU cannot be determined. +#[doc(hidden)] +#[deprecated(since = "0.1.2", note = "Use `interface_and_mtu()` instead")] pub fn interface_mtu(remote: &SocketAddr) -> Result { interface_and_mtu(remote).map(|(_, mtu)| mtu) } +#[doc(hidden)] +#[deprecated(since = "0.1.2", note = "Use `interface_and_mtu()` instead")] +pub fn get_interface_mtu(remote: &SocketAddr) -> Result { + interface_and_mtu(remote).map(|(_, mtu)| mtu) +} + #[cfg(test)] mod test { use std::net::ToSocketAddrs; @@ -306,8 +287,8 @@ mod test { .unwrap() .find(|a| a.is_ipv4() == ipv4); if let Some(addr) = addr { - match super::interface_mtu(&addr) { - Ok(mtu) => assert_eq!(mtu, expected), + match super::interface_and_mtu(&addr) { + Ok((_, mtu)) => assert_eq!(mtu, expected), Err(e) => { // Some GitHub runners don't have IPv6. Just warn if we can't get the MTU. assert!(addr.is_ipv6());