/ console / types / boolean / src / lib.rs
lib.rs
 1  // Copyright (c) 2019-2025 Alpha-Delta Network Inc.
 2  // This file is part of the alphavm library.
 3  
 4  // Licensed under the Apache License, Version 2.0 (the "License");
 5  // you may not use this file except in compliance with the License.
 6  // You may obtain a copy of the License at:
 7  
 8  // http://www.apache.org/licenses/LICENSE-2.0
 9  
10  // Unless required by applicable law or agreed to in writing, software
11  // distributed under the License is distributed on an "AS IS" BASIS,
12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  // See the License for the specific language governing permissions and
14  // limitations under the License.
15  
16  #![cfg_attr(test, allow(clippy::assertions_on_result_states))]
17  #![warn(clippy::cast_possible_truncation)]
18  
19  mod bitwise;
20  mod bytes;
21  mod from_bits;
22  mod parse;
23  mod random;
24  mod serialize;
25  mod size_in_bits;
26  mod size_in_bytes;
27  mod to_bits;
28  
29  pub use alphavm_console_network_environment::prelude::*;
30  
31  use core::marker::PhantomData;
32  
33  #[derive(Copy, Clone, PartialEq, Eq, Hash)]
34  pub struct Boolean<E: Environment> {
35      /// The underlying boolean.
36      boolean: bool,
37      /// PhantomData.
38      _phantom: PhantomData<E>,
39  }
40  
41  impl<E: Environment> BooleanTrait for Boolean<E> {}
42  
43  impl<E: Environment> Boolean<E> {
44      /// Initializes a new boolean.
45      pub const fn new(boolean: bool) -> Self {
46          Self { boolean, _phantom: PhantomData }
47      }
48  
49      /// Initializes a `false` boolean.
50      #[deprecated(since = "0.1.0", note = "This is used for **testing** purposes")]
51      pub const fn zero() -> Self {
52          Self::new(false)
53      }
54  }
55  
56  impl<E: Environment> TypeName for Boolean<E> {
57      /// Returns the type name as a string.
58      #[inline]
59      fn type_name() -> &'static str {
60          "boolean"
61      }
62  }
63  
64  impl<E: Environment> Deref for Boolean<E> {
65      type Target = bool;
66  
67      #[inline]
68      fn deref(&self) -> &Self::Target {
69          &self.boolean
70      }
71  }
72  
73  impl<E: Environment> PartialEq<Boolean<E>> for bool {
74      fn eq(&self, other: &Boolean<E>) -> bool {
75          *self == **other
76      }
77  }