viffy 0.1.5

SoA + SIMD automata generator
Documentation
#![feature(associated_type_defaults)]
#![feature(sync_unsafe_cell)]
#![feature(allocator_api)]
#![feature(test)]

pub mod prelude;
pub mod date;
pub mod math;
pub mod test;
pub mod random;
pub mod automata;
pub mod algos;
pub mod generator;
pub mod text;
pub mod graphics;
//pub mod huge_singleton_allocator;
//pub mod dense_linked_list;
mod serializer;
mod vector;
mod data;
mod num_traits;

pub use crate::vector::*;
pub use crate::data::*;
pub use crate::num_traits::*;
pub use crate::serializer::*;

pub type PoolVec<T> = Vec<T>;
pub type PoolSet<T> = std::collections::BTreeSet<T>;
pub type PoolMap<K, V> = std::collections::BTreeMap<K, V>;

#[derive(Default, Clone, Copy, Debug)]
pub struct Color4(pub f32, pub f32, pub f32, pub f32);
#[derive(Default, Clone, Copy, Debug)]
pub struct Color3(pub f32, pub f32, pub f32);
#[derive(Default, Clone, Copy, Debug)]
pub struct AlnumPacked3(pub u8, pub u8, pub u8);

/// https://stackoverflow.com/questions/38088067/equivalent-of-func-or-function-in-rust
#[macro_export]
macro_rules! function_name {
	($x:expr) => {{
		fn f() {}
		fn type_name_of<T>(_: T) -> &'static str { std::any::type_name::<T>() }
		let name = type_name_of(f);
		name.strip_suffix("::f").unwrap()
			.strip_prefix($x).unwrap()
	}}
}

/// This cell is entirely unsound with the normal rust memory model
/// Use it only with viffy world state AND if you can guarantee
/// your reads will not clash with your writes
#[derive(Default, Debug)]
pub struct ShareableCell<T>(std::cell::SyncUnsafeCell<T>);
impl<T> ShareableCell<T> {
	pub fn new(value: T) -> Self {
		Self(std::cell::SyncUnsafeCell::new(value))
	}
	pub fn borrow(&self) -> &T {
		unsafe { self.0.get().as_ref().unwrap() }
	}
	pub fn borrow_mut(&self) -> &mut T {
		unsafe { self.0.get().as_mut().unwrap() }
	}
}
unsafe impl<T> Sync for ShareableCell<T> {}

// DO NOT use in anything other than as a generic association with
// IsOrdered
pub type TrueType = bool;
pub type FalseType = ();