add UnwrapInfallible to Result
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
a5de27442a
commit
6001014078
3 changed files with 21 additions and 7 deletions
|
@ -3,10 +3,11 @@ mod log_debug_err;
|
||||||
mod log_err;
|
mod log_err;
|
||||||
mod map_expect;
|
mod map_expect;
|
||||||
mod not_found;
|
mod not_found;
|
||||||
|
mod unwrap_infallible;
|
||||||
|
|
||||||
pub use self::{
|
pub use self::{
|
||||||
debug_inspect::DebugInspect, log_debug_err::LogDebugErr, log_err::LogErr, map_expect::MapExpect,
|
debug_inspect::DebugInspect, log_debug_err::LogDebugErr, log_err::LogErr, map_expect::MapExpect,
|
||||||
not_found::NotFound,
|
not_found::NotFound, unwrap_infallible::UnwrapInfallible,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub type Result<T = (), E = crate::Error> = std::result::Result<T, E>;
|
pub type Result<T = (), E = crate::Error> = std::result::Result<T, E>;
|
||||||
|
|
17
src/core/result/unwrap_infallible.rs
Normal file
17
src/core/result/unwrap_infallible.rs
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
use std::convert::Infallible;
|
||||||
|
|
||||||
|
use super::{DebugInspect, Result};
|
||||||
|
use crate::error;
|
||||||
|
|
||||||
|
pub trait UnwrapInfallible<T> {
|
||||||
|
fn unwrap_infallible(self) -> T;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> UnwrapInfallible<T> for Result<T, Infallible> {
|
||||||
|
#[inline]
|
||||||
|
fn unwrap_infallible(self) -> T {
|
||||||
|
// SAFETY: Branchless unwrap for errors that can never happen. In debug
|
||||||
|
// mode this is asserted.
|
||||||
|
unsafe { self.debug_inspect_err(error::infallible).unwrap_unchecked() }
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,7 +10,7 @@ use axum::{
|
||||||
extract::{connect_info::IntoMakeServiceWithConnectInfo, Request},
|
extract::{connect_info::IntoMakeServiceWithConnectInfo, Request},
|
||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
use conduit::{debug, debug_error, error::infallible, info, trace, warn, Err, Result, Server};
|
use conduit::{debug, debug_error, info, result::UnwrapInfallible, trace, warn, Err, Result, Server};
|
||||||
use hyper::{body::Incoming, service::service_fn};
|
use hyper::{body::Incoming, service::service_fn};
|
||||||
use hyper_util::{
|
use hyper_util::{
|
||||||
rt::{TokioExecutor, TokioIo},
|
rt::{TokioExecutor, TokioIo},
|
||||||
|
@ -62,11 +62,7 @@ async fn accept(
|
||||||
let socket = TokioIo::new(socket);
|
let socket = TokioIo::new(socket);
|
||||||
trace!(?listener, ?socket, ?remote, "accepted");
|
trace!(?listener, ?socket, ?remote, "accepted");
|
||||||
|
|
||||||
let called = app
|
let called = app.call(NULL_ADDR).await.unwrap_infallible();
|
||||||
.call(NULL_ADDR)
|
|
||||||
.await
|
|
||||||
.inspect_err(infallible)
|
|
||||||
.expect("infallible");
|
|
||||||
|
|
||||||
let service = move |req: Request<Incoming>| called.clone().oneshot(req);
|
let service = move |req: Request<Incoming>| called.clone().oneshot(req);
|
||||||
let handler = service_fn(service);
|
let handler = service_fn(service);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue