parent
e30d51a599
commit
79f657b462
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Created on Fri Jun 25 2021
|
||||||
|
*
|
||||||
|
* This file is a part of Skytable
|
||||||
|
* Skytable (formerly known as TerrabaseDB or Skybase) is a free and open-source
|
||||||
|
* NoSQL database written by Sayan Nandan ("the Author") with the
|
||||||
|
* vision to provide flexibility in data modelling without compromising
|
||||||
|
* on performance, queryability or scalability.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021, Sayan Nandan <ohsayan@outlook.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/// # Unsafe unwrapping
|
||||||
|
///
|
||||||
|
/// This trait provides a method `unsafe_unwrap` that is potentially unsafe and has
|
||||||
|
/// the ability to **violate multiple safety gurantees** that rust provides. So,
|
||||||
|
/// if you get `SIGILL`s or `SIGSEGV`s, by using this trait, blame yourself.
|
||||||
|
pub unsafe trait Unwrappable<T> {
|
||||||
|
/// Unwrap a _nullable_ (almost) type to get its value while asserting that the value
|
||||||
|
/// cannot ever be null
|
||||||
|
///
|
||||||
|
/// ## Safety
|
||||||
|
/// The trait is unsafe, and so is this function. You can wreck potential havoc if you
|
||||||
|
/// use this heedlessly
|
||||||
|
///
|
||||||
|
unsafe fn unsafe_unwrap(self) -> T;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe impl<T, E> Unwrappable<T> for Result<T, E> {
|
||||||
|
unsafe fn unsafe_unwrap(self) -> T {
|
||||||
|
match self {
|
||||||
|
Ok(t) => t,
|
||||||
|
Err(_) => core::hint::unreachable_unchecked(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe impl<T> Unwrappable<T> for Option<T> {
|
||||||
|
unsafe fn unsafe_unwrap(self) -> T {
|
||||||
|
match self {
|
||||||
|
Some(t) => t,
|
||||||
|
None => core::hint::unreachable_unchecked(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue