hexga_core/
utils.rs

1pub use rayon::prelude::*;
2pub use default_is_triple_underscore::*;
3
4pub trait Toggleable
5{
6    fn toggle(&mut self);
7}
8impl Toggleable for bool
9{
10    #[inline(always)]
11    fn toggle(&mut self) 
12    {
13        use std::ops::Not;
14        *self = self.not();
15    }
16}
17
18pub trait ToDebug
19{
20    fn to_debug(&self) -> String;
21}
22impl<T> ToDebug for T where T : std::fmt::Debug
23{
24    #[inline(always)]
25    fn to_debug(&self) -> String {
26        format!("{:?}", self)
27    }
28}
29
30/// Useful to silence/convert to void some Err.
31/// 
32/// Some of my lib will probably have proper error type instead of () (Look for `#proper_error` to know which error type are temporary) when I will have time to add them
33pub trait ResultExtension<T>
34{
35    fn ok_or_void(self) -> Result<T,()>;
36}
37impl<T,E> ResultExtension<T> for Result<T,E>
38{
39    #[inline(always)]
40    fn ok_or_void(self) -> Result<T,()> {
41        self.map_err(|_| ())
42    }
43}
44impl<T> ResultExtension<T> for Option<T>
45{
46    #[inline(always)]
47    fn ok_or_void(self) -> Result<T,()> {
48        self.ok_or(())
49    }
50}
51
52
53/*
54// Eq is imply by Ord, but I prefer to make sure this is visible
55/// A key that can be used in an HashMap (Hash + Eq), but also in a BTreeMap (Ord + Eq)
56pub trait UniversalKey : Hash + Eq + Ord {}
57impl<T> UniversalKey for T where T: Hash + Eq + Ord {}
58*/