|
|
@ -26,22 +26,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
use core::ops::Index;
|
|
|
|
use core::ops::Index;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub type BytesBoolTable = BoolTable<&'static [u8]>;
|
|
|
|
|
|
|
|
pub type BytesNicheLUT = NicheLUT<&'static [u8]>;
|
|
|
|
|
|
|
|
|
|
|
|
/// A two-value boolean LUT
|
|
|
|
/// A two-value boolean LUT
|
|
|
|
pub struct BoolTable {
|
|
|
|
pub struct BoolTable<T> {
|
|
|
|
base: [&'static [u8]; 2],
|
|
|
|
base: [T; 2],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl BoolTable {
|
|
|
|
impl<T> BoolTable<T> {
|
|
|
|
/// Supply values in the order: `if_true` and `if_false`
|
|
|
|
/// Supply values in the order: `if_true` and `if_false`
|
|
|
|
pub const fn new(if_true: &'static [u8], if_false: &'static [u8]) -> Self {
|
|
|
|
pub const fn new(if_true: T, if_false: T) -> Self {
|
|
|
|
Self {
|
|
|
|
Self {
|
|
|
|
base: [if_false, if_true],
|
|
|
|
base: [if_false, if_true],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Index<bool> for BoolTable {
|
|
|
|
impl<T> Index<bool> for BoolTable<T> {
|
|
|
|
type Output = &'static [u8];
|
|
|
|
type Output = T;
|
|
|
|
fn index(&self, index: bool) -> &Self::Output {
|
|
|
|
fn index(&self, index: bool) -> &Self::Output {
|
|
|
|
unsafe { &*self.base.as_ptr().add(index as usize) }
|
|
|
|
unsafe { &*self.base.as_ptr().add(index as usize) }
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -51,17 +54,13 @@ impl Index<bool> for BoolTable {
|
|
|
|
/// structure
|
|
|
|
/// structure
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// **Warning:** This is a terrible opt and only works on the Rust ABI
|
|
|
|
/// **Warning:** This is a terrible opt and only works on the Rust ABI
|
|
|
|
pub struct NicheLUT {
|
|
|
|
pub struct NicheLUT<T> {
|
|
|
|
base: [&'static [u8]; 3],
|
|
|
|
base: [T; 3],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl NicheLUT {
|
|
|
|
impl<T> NicheLUT<T> {
|
|
|
|
/// Supply values in the following order: [`if_none`, `if_true`, `if_false`]
|
|
|
|
/// Supply values in the following order: [`if_none`, `if_true`, `if_false`]
|
|
|
|
pub const fn new(
|
|
|
|
pub const fn new(if_none: T, if_true: T, if_false: T) -> Self {
|
|
|
|
if_none: &'static [u8],
|
|
|
|
|
|
|
|
if_true: &'static [u8],
|
|
|
|
|
|
|
|
if_false: &'static [u8],
|
|
|
|
|
|
|
|
) -> Self {
|
|
|
|
|
|
|
|
Self {
|
|
|
|
Self {
|
|
|
|
// 0 == S(F); 1 == S(T); 2 == NULL
|
|
|
|
// 0 == S(F); 1 == S(T); 2 == NULL
|
|
|
|
base: [if_false, if_true, if_none],
|
|
|
|
base: [if_false, if_true, if_none],
|
|
|
@ -69,8 +68,8 @@ impl NicheLUT {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Index<Option<bool>> for NicheLUT {
|
|
|
|
impl<T> Index<Option<bool>> for NicheLUT<T> {
|
|
|
|
type Output = &'static [u8];
|
|
|
|
type Output = T;
|
|
|
|
fn index(&self, idx: Option<bool>) -> &Self::Output {
|
|
|
|
fn index(&self, idx: Option<bool>) -> &Self::Output {
|
|
|
|
unsafe {
|
|
|
|
unsafe {
|
|
|
|
&*self
|
|
|
|
&*self
|
|
|
|