1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
pub fn compare_strs<T: PartialEq + std::fmt::Debug> (a: &[T], b: &[T], l: usize) -> bool {
  for i in 0..l {
    if a[i] != b[i] { 
      return false
    }
  }

  true
}

pub trait BoolAsResult {
  fn as_result (self) -> Result<(), std::option::NoneError>;
}

impl BoolAsResult for bool {
  fn as_result (self) -> Result<(), std::option::NoneError> {
    match self {
      true => Ok(()),
      false => Err(std::option::NoneError)
    }
  }
}

pub trait BoolAsOption {
  fn as_option (self) -> Option<()>;
}

impl BoolAsOption for bool {
  fn as_option (self) -> Option<()> {
    match self {
      true => Some(()),
      false => None
    }
  }
}

macro_rules! impl_Debug_from_Display {
  ($ty: path) => {
    impl std::fmt::Debug for $ty {
      fn fmt (&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        std::fmt::Display::fmt(self, f)
      }
    }
  };
}