From 4481f38023e6be94080272a4d457741ac120a2ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Sun, 27 Oct 2024 19:03:22 +0100 Subject: [PATCH] Remove custom NeverOkResult trait and instead use new Rust 1.82 matching --- src/bin/tcp2udp.rs | 6 ++---- src/forward_traffic.rs | 3 +-- src/lib.rs | 12 ------------ 3 files changed, 3 insertions(+), 18 deletions(-) diff --git a/src/bin/tcp2udp.rs b/src/bin/tcp2udp.rs index 5ff1819..cb86f24 100644 --- a/src/bin/tcp2udp.rs +++ b/src/bin/tcp2udp.rs @@ -4,7 +4,7 @@ use clap::Parser; use err_context::ErrorExt as _; use std::num::NonZeroU8; -use udp_over_tcp::{tcp2udp, NeverOkResult}; +use udp_over_tcp::tcp2udp; #[derive(Debug, Parser)] #[command( @@ -30,9 +30,7 @@ fn main() { let runtime = create_runtime(options.threads); - let error = runtime - .block_on(tcp2udp::run(options.tcp2udp_options)) - .into_error(); + let Err(error) = runtime.block_on(tcp2udp::run(options.tcp2udp_options)); log::error!("Error: {}", error.display("\nCaused by: ")); std::process::exit(1); } diff --git a/src/forward_traffic.rs b/src/forward_traffic.rs index cf08b8a..9914170 100644 --- a/src/forward_traffic.rs +++ b/src/forward_traffic.rs @@ -1,4 +1,3 @@ -use crate::NeverOkResult; use err_context::BoxedErrorExt as _; use err_context::ResultExt as _; use futures::future::select; @@ -41,7 +40,7 @@ pub async fn process_udp_over_tcp( } }; let udp2tcp = async move { - let error = process_udp2tcp(udp_in, tcp_out).await.into_error(); + let Err(error) = process_udp2tcp(udp_in, tcp_out).await; log::error!("Error: {}", error.display("\nCaused by: ")); }; diff --git a/src/lib.rs b/src/lib.rs index b0a9db4..274b9cb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -95,15 +95,3 @@ pub use tcp_options::{ApplyTcpOptionsError, ApplyTcpOptionsErrorKind, TcpOptions /// Size of the header (in bytes) that is prepended to each datagram in the TCP stream. pub use forward_traffic::HEADER_LEN; - -/// Helper trait for `Result` types. Allows getting the `E` value -/// in a way that is guaranteed to not panic. -pub trait NeverOkResult { - fn into_error(self) -> E; -} - -impl NeverOkResult for Result { - fn into_error(self) -> E { - self.expect_err("Result can't be Ok variant") - } -}