viffy 0.1.5

SoA + SIMD automata generator
Documentation
use std::ops::{Add, Div, Mul, Sub};
use crate as viffy;
use crate::ContainerIndex;

pub trait NumericTrait: Copy + Default
	+ Add<Output = Self> + Sub<Output = Self>
	+ Mul<Output = Self> + Div<Output = Self>
{
	fn parallel_seq() -> bool { false }
}
impl NumericTrait for i8 {}
impl NumericTrait for i16 {}
impl NumericTrait for i32 {}
impl NumericTrait for i64 {}
impl NumericTrait for u8 {}
impl NumericTrait for u16 {}
impl NumericTrait for u32 {}
impl NumericTrait for u64 {}
impl NumericTrait for f32 {}
impl NumericTrait for f64 {}
impl NumericTrait for viffy::IntegerVector {}
impl NumericTrait for viffy::ContigousIntegerVector {
	fn parallel_seq() -> bool { true }
}
impl NumericTrait for viffy::FloatVector {}

/// DO NOT implement these on vectors
pub trait SerialNumericTrait: Copy + Default
	+ Add<Output = Self> + Sub<Output = Self>
	+ Mul<Output = Self> + Div<Output = Self>
{
	fn from_num(_: i32) -> Self { unsafe { std::hint::unreachable_unchecked() } }
	fn from_float(_: f32) -> Self { unsafe { std::hint::unreachable_unchecked() } }
	fn into_num(self) -> i32 { unsafe { std::hint::unreachable_unchecked() } }
	fn into_float(self) -> f32 { unsafe { std::hint::unreachable_unchecked() } }
	fn into_tag<C>(self) -> C
    where
        C: ContainerIndex + From<C::ValueType>,
        C::ValueType: LossyFrom<Self>
    {
		C::from(C::ValueType::from_lossy(self))
	}
}
impl SerialNumericTrait for i8 {}
impl SerialNumericTrait for i16 {}
impl SerialNumericTrait for i32 {}
impl SerialNumericTrait for i64 {}
impl SerialNumericTrait for u8 {}
impl SerialNumericTrait for u16 {}
impl SerialNumericTrait for u32 {}
impl SerialNumericTrait for u64 {}
impl SerialNumericTrait for f32 {}
impl SerialNumericTrait for f64 {}

pub trait LossyFrom<T: SerialNumericTrait>: SerialNumericTrait {
	fn from_lossy(x: T) -> Self;
}
macro_rules! lossy_ops {
	($($x:ident $y:ident)*) => {
		$(impl LossyFrom<$x> for $y { fn from_lossy(x: $x) -> Self { x as Self } })*
	};
}
lossy_ops!{
	u8  u8 u8  u16 u8  i16 u8  i8 u8  i32 u8  u32 u8  f32 u8  f64 u8  i64 u8  u64
	i8  u8 i8  u16 i8  i16 i8  i8 i8  i32 i8  u32 i8  f32 i8  f64 i8  i64 i8  u64
	u16 u8 u16 u16 u16 i16 u16 i8 u16 i32 u16 u32 u16 f32 u16 f64 u16 i64 u16 u64
	i16 u8 i16 u16 i16 i16 i16 i8 i16 i32 i16 u32 i16 f32 i16 f64 i16 i64 i16 u64
	u32 u8 u32 u16 u32 i16 u32 i8 u32 i32 u32 u32 u32 f32 u32 f64 u32 i64 u32 u64
	i32 u8 i32 u16 i32 i16 i32 i8 i32 i32 i32 u32 i32 f32 i32 f64 i32 i64 i32 u64
	u64 u8 u64 u16 u64 i16 u64 i8 u64 i32 u64 u32 u64 f32 u64 f64 u64 i64 u64 u64
	i64 u8 i64 u16 i64 i16 i64 i8 i64 i32 i64 u32 i64 f32 i64 f64 i64 i64 i64 u64
	f32 u8 f32 u16 f32 i16 f32 i8 f32 i32 f32 u32 f32 f32 f32 f64 f32 i64 f32 u64
	f64 u8 f64 u16 f64 i16 f64 i8 f64 i32 f64 u32 f64 f32 f64 f64 f64 i64 f64 u64
}