snarkvm_console_types_boolean/
lib.rs

1// Copyright 2024-2025 Aleo Network Foundation
2// This file is part of the snarkVM 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
19mod bitwise;
20mod bytes;
21mod from_bits;
22mod parse;
23mod random;
24mod serialize;
25mod size_in_bits;
26mod size_in_bytes;
27mod to_bits;
28
29pub use snarkvm_console_network_environment::prelude::*;
30
31use core::marker::PhantomData;
32
33#[derive(Copy, Clone, PartialEq, Eq, Hash)]
34pub struct Boolean<E: Environment> {
35    /// The underlying boolean.
36    boolean: bool,
37    /// PhantomData.
38    _phantom: PhantomData<E>,
39}
40
41impl<E: Environment> BooleanTrait for Boolean<E> {}
42
43impl<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
56impl<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
64impl<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
73impl<E: Environment> PartialEq<Boolean<E>> for bool {
74    fn eq(&self, other: &Boolean<E>) -> bool {
75        *self == **other
76    }
77}