From 06ac3bd8377549a017ae2bf0509e132f6939453b Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Mon, 2 Sep 2024 15:42:35 +0300 Subject: [PATCH 1/6] doc: Add an example --- src/lib.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 4af7c4a..0400db3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,7 +20,23 @@ fn default_result() -> Result { )) } -/// Return the MTU of the interface that is used to reach the given remote socket address. +/// 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.) +/// +/// # Examples +/// +/// ``` +/// use std::net::ToSocketAddrs; +/// use mtu::get_interface_mtu; +/// +/// let saddr ="localhost:443".to_socket_addrs().unwrap().next().unwrap(); +/// let mtu = get_interface_mtu(&saddr).unwrap(); +/// println!("MTU towards {:?} is {}", saddr, mtu); +/// ``` /// /// # Errors /// From 902d5875cfd1dafca55b23ff57214dc0d077fba0 Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Mon, 2 Sep 2024 15:45:09 +0300 Subject: [PATCH 2/6] Reformat and add `.rustfmt.toml` --- .rustfmt.toml | 13 +++++++++++++ src/lib.rs | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .rustfmt.toml diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 0000000..39c3ae7 --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,13 @@ +# Keep in sync with `Cargo.toml` `edition`. +# +# `rustfmt` envoked not through `cargo fmt` but directly does not pick up Rust +# edition in `Cargo.toml`. Thus duplicate here. +edition = "2021" + +comment_width=100 +wrap_comments=true + +imports_granularity="Crate" +group_imports="StdExternalCrate" + +format_code_in_doc_comments=true diff --git a/src/lib.rs b/src/lib.rs index 0400db3..9e625f3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,9 +31,10 @@ fn default_result() -> Result { /// /// ``` /// use std::net::ToSocketAddrs; +/// /// use mtu::get_interface_mtu; /// -/// let saddr ="localhost:443".to_socket_addrs().unwrap().next().unwrap(); +/// let saddr = "localhost:443".to_socket_addrs().unwrap().next().unwrap(); /// let mtu = get_interface_mtu(&saddr).unwrap(); /// println!("MTU towards {:?} is {}", saddr, mtu); /// ``` From c8740874e764557c99938c4005f12151c5ce4859 Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Mon, 2 Sep 2024 17:27:49 +0300 Subject: [PATCH 3/6] Fix from @mxinden --- .github/workflows/check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index c5a8e8c..3eaf585 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -88,7 +88,7 @@ jobs: for sanitizer in $SANITIZERS; do echo "Running tests with $sanitizer sanitizer..." - RUSTFLAGS="-Z sanitizer=$sanitizer" cargo +nightly test -Z build-std --target $TARGET + RUSTFLAGS="-Z sanitizer=$sanitizer" RUSTDOCFLAGS="-Z sanitizer=$sanitizer" cargo +nightly test -Z build-std --target $TARGET done - name: Check formatting From e93c3137f5ecd468f8d62e4edf707b5983f581ec Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Mon, 2 Sep 2024 17:42:26 +0300 Subject: [PATCH 4/6] Update src/lib.rs Co-authored-by: Max Inden --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 87bede4..c279494 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,7 +21,7 @@ fn default_result() -> Result { } /// Return the maximum transmission unit (MTU) of the local network interface towards the -/// destination `SocketAddr` given in `remote`. +/// 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 From bdfa8dcc47cfebfcaa5753f61b9383129ff72fe8 Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Mon, 2 Sep 2024 17:42:47 +0300 Subject: [PATCH 5/6] Update src/lib.rs Co-authored-by: Max Inden --- src/lib.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c279494..2c9a971 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,11 +30,9 @@ fn default_result() -> Result { /// # Examples /// /// ``` -/// use std::net::ToSocketAddrs; -/// -/// use mtu::get_interface_mtu; -/// -/// let saddr = "localhost:443".to_socket_addrs().unwrap().next().unwrap(); +/// # use std::net::ToSocketAddrs; +/// # use mtu::get_interface_mtu; +/// let saddr = "127.0.0.1:443".parse().unwrap(); /// let mtu = get_interface_mtu(&saddr).unwrap(); /// println!("MTU towards {:?} is {}", saddr, mtu); /// ``` From 473763d04e9f44f1c7ec42d259ef95bdb69db9ce Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Mon, 2 Sep 2024 17:47:13 +0300 Subject: [PATCH 6/6] Remove `use` comments --- src/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2c9a971..c2a939b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,10 +30,8 @@ fn default_result() -> Result { /// # Examples /// /// ``` -/// # use std::net::ToSocketAddrs; -/// # use mtu::get_interface_mtu; /// let saddr = "127.0.0.1:443".parse().unwrap(); -/// let mtu = get_interface_mtu(&saddr).unwrap(); +/// let mtu = mtu::get_interface_mtu(&saddr).unwrap(); /// println!("MTU towards {:?} is {}", saddr, mtu); /// ``` ///