move infallible handling into error
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
4cc92dd175
commit
4600c7f32d
3 changed files with 19 additions and 18 deletions
|
@ -196,7 +196,11 @@ impl UnwindSafe for Error {}
|
|||
impl RefUnwindSafe for Error {}
|
||||
|
||||
impl From<Infallible> for Error {
|
||||
fn from(i: Infallible) -> Self { match i {} }
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
fn from(_i: Infallible) -> Self {
|
||||
panic!("infallible error should never exist");
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for Error {
|
||||
|
@ -273,6 +277,12 @@ pub fn inspect_debug_log<E: fmt::Debug>(error: &E) {
|
|||
debug_error!("{error:?}");
|
||||
}
|
||||
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
pub fn infallible(_e: &Infallible) {
|
||||
panic!("infallible error should never exist");
|
||||
}
|
||||
|
||||
impl axum::response::IntoResponse for Error {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
let response: UiaaResponse = self.into();
|
||||
|
|
|
@ -26,21 +26,8 @@ pub use string::{str_from_bytes, string_from_bytes};
|
|||
pub use sys::available_parallelism;
|
||||
pub use time::now_millis as millis_since_unix_epoch;
|
||||
|
||||
use crate::Result;
|
||||
|
||||
pub fn clamp<T: Ord>(val: T, min: T, max: T) -> T { cmp::min(cmp::max(val, min), max) }
|
||||
|
||||
/// Boilerplate for wraps which are typed to never error.
|
||||
///
|
||||
/// * <https://doc.rust-lang.org/std/convert/enum.Infallible.html>
|
||||
#[must_use]
|
||||
pub fn unwrap_infallible<T>(result: Result<T, std::convert::Infallible>) -> T {
|
||||
match result {
|
||||
Ok(val) => val,
|
||||
Err(err) => match err {},
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn generate_keypair() -> Vec<u8> {
|
||||
let mut value = rand::string(8).as_bytes().to_vec();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue