Skip to content

Commit

Permalink
Remove custom NeverOkResult trait and instead use new Rust 1.82 matching
Browse files Browse the repository at this point in the history
  • Loading branch information
faern committed Oct 27, 2024
1 parent 24b2e25 commit 4481f38
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 18 deletions.
6 changes: 2 additions & 4 deletions src/bin/tcp2udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions src/forward_traffic.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::NeverOkResult;
use err_context::BoxedErrorExt as _;
use err_context::ResultExt as _;
use futures::future::select;
Expand Down Expand Up @@ -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: "));
};

Expand Down
12 changes: 0 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Infallible, E>` types. Allows getting the `E` value
/// in a way that is guaranteed to not panic.
pub trait NeverOkResult<E> {
fn into_error(self) -> E;
}

impl<E> NeverOkResult<E> for Result<std::convert::Infallible, E> {
fn into_error(self) -> E {
self.expect_err("Result<Infallible, _> can't be Ok variant")
}
}

0 comments on commit 4481f38

Please sign in to comment.