Skip to main content

grafix_toolbox/kit/
policies.rs

1pub mod ext {
2	pub use super::func::{chksum, chksum::ref_UUID, file as FS, logger, rand, serde::ser, slicing};
3	pub use super::{memory::Ptr, pre::lazy, profiling};
4}
5
6#[macro_export]
7macro_rules! trait_alias {
8	($p: vis $t: ident, $($b: tt)+) => {
9		$p trait $t: $($b)+ {}
10		impl<S: $($b)+> $t for S {} // TODO replace with trait aliases
11	};
12	($t: ident, $($b: tt)+) => {
13		trait_alias!(pub(self) $t, $($b)+);
14	};
15}
16
17pub mod pre {
18	pub use super::func::{ext::*, faster::*, n_iter::*, range::*, result::*, vec::*};
19	pub use super::{math::pre::*, types::*};
20
21	pub fn type_name<T: ?Sized>() -> String {
22		std::any::type_name::<T>()
23			.split_inclusive(['<', '>', '(', ')', ','])
24			.map(|s| if let Some(i) = s.rfind("::") { &s[i + 2..] } else { s })
25			.collect()
26	}
27
28	trait_alias!(pub SendS, 'static + Send);
29
30	#[cfg(feature = "adv_fs")]
31	trait_alias!(pub TrivialBound, 'static + std::fmt::Debug + Default + Copy + PartialEq + serde::Serialize + serde::de::DeserializeOwned);
32	#[cfg(not(feature = "adv_fs"))]
33	trait_alias!(pub TrivialBound, 'static + std::fmt::Debug + Default + Copy + PartialEq);
34
35	pub trait Fut<T>: Future<Output = T> + Send {} // TODO drop when AsyncFn is usable
36	impl<T, S: Future<Output = T> + Send> Fut<T> for S {}
37}
38
39#[macro_export]
40macro_rules! impl_trait_for {
41	($trait: ty = $($types: ty),+) => {
42		$(impl $trait for $types {})+
43	};
44}
45
46#[macro_export]
47macro_rules! map_variant {
48	($t: pat = $e: expr => $do: expr) => {{ if let $t = $e { Some($do) } else { None } }};
49}
50#[macro_export]
51macro_rules! or_map {
52	($v: ident = $t: pat => $do: expr) => {{
53		if let $t = $v {
54			*$v = $do
55		}
56	}};
57}
58
59#[macro_use]
60mod memory;
61#[macro_use]
62mod func;
63#[macro_use]
64mod types;
65
66pub mod math;
67pub mod profiling;
68pub mod task;