Move unhandled macro from database utils to core utils.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -20,6 +20,7 @@ pub mod sys;
|
||||
mod tests;
|
||||
pub mod time;
|
||||
pub mod two_phase_counter;
|
||||
pub mod unhandled;
|
||||
|
||||
pub use ::ctor::{ctor, dtor};
|
||||
pub use ::tuwunel_macros::implement;
|
||||
|
||||
33
src/core/utils/unhandled.rs
Normal file
33
src/core/utils/unhandled.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
//! Indicate a branch which will never be taken. This induces optimal codegen in
|
||||
//! release-mode by emitting unsafe unreachable_unchecked(). In debug-mode it
|
||||
//! emits unimplemented() to panic on misplacement.
|
||||
|
||||
#[cfg(disable)] // activate when more stable and callsites are vetted.
|
||||
// #[cfg(not(debug_assertions))]
|
||||
#[macro_export]
|
||||
macro_rules! unhandled {
|
||||
($msg:literal) => {
|
||||
// SAFETY: Eliminates branches never encountered in the codebase. This can
|
||||
// promote optimization and reduce codegen. The developer must verify for every
|
||||
// invoking callsite that the unhandled type is in no way involved and could not
|
||||
// possibly be encountered.
|
||||
unsafe {
|
||||
std::hint::unreachable_unchecked();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
//#[cfg(debug_assertions)]
|
||||
#[macro_export]
|
||||
macro_rules! unhandled {
|
||||
($msg:literal) => {
|
||||
$crate::maybe_unhandled!($msg);
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! maybe_unhandled {
|
||||
($msg:literal) => {
|
||||
unimplemented!($msg)
|
||||
};
|
||||
}
|
||||
@@ -3,11 +3,10 @@ use serde::{
|
||||
de::{DeserializeSeed, Visitor},
|
||||
};
|
||||
use tuwunel_core::{
|
||||
Error, Result, arrayvec::ArrayVec, checked, debug::DebugInspect, err, utils::string,
|
||||
Error, Result, arrayvec::ArrayVec, checked, debug::DebugInspect, err, unhandled,
|
||||
utils::string,
|
||||
};
|
||||
|
||||
use crate::util::unhandled;
|
||||
|
||||
/// Deserialize into T from buffer.
|
||||
#[cfg_attr(
|
||||
unabridged,
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
use std::{io::Write, mem::replace};
|
||||
|
||||
use serde::{Deserialize, Serialize, ser};
|
||||
use tuwunel_core::{Error, Result, debug::type_name, err, result::DebugInspect};
|
||||
|
||||
use crate::util::unhandled;
|
||||
use tuwunel_core::{Error, Result, debug::type_name, err, result::DebugInspect, unhandled};
|
||||
|
||||
#[inline]
|
||||
pub fn serialize_to_vec<T: Serialize>(val: T) -> Result<Vec<u8>> {
|
||||
|
||||
@@ -1,29 +1,6 @@
|
||||
use rocksdb::{Direction, ErrorKind, IteratorMode};
|
||||
use tuwunel_core::Result;
|
||||
|
||||
//#[cfg(debug_assertions)]
|
||||
macro_rules! unhandled {
|
||||
($msg:literal) => {
|
||||
unimplemented!($msg)
|
||||
};
|
||||
}
|
||||
|
||||
// activate when stable; we're not ready for this yet
|
||||
#[cfg(disable)] // #[cfg(not(debug_assertions))]
|
||||
macro_rules! unhandled {
|
||||
($msg:literal) => {
|
||||
// SAFETY: Eliminates branches for serializing and deserializing types never
|
||||
// encountered in the codebase. This can promote optimization and reduce
|
||||
// codegen. The developer must verify for every invoking callsite that the
|
||||
// unhandled type is in no way involved and could not possibly be encountered.
|
||||
unsafe {
|
||||
std::hint::unreachable_unchecked();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub(crate) use unhandled;
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn _into_direction(mode: &IteratorMode<'_>) -> Direction {
|
||||
use Direction::{Forward, Reverse};
|
||||
|
||||
Reference in New Issue
Block a user