/ console / program / src / data / literal / cast / boolean.rs
boolean.rs
 1  // Copyright (c) 2025-2026 ACDC Network
 2  // This file is part of the alphavm library.
 3  //
 4  // Alpha Chain | Delta Chain Protocol
 5  // International Monetary Graphite.
 6  //
 7  // Derived from Aleo (https://aleo.org) and ProvableHQ (https://provable.com).
 8  // They built world-class ZK infrastructure. We installed the EASY button.
 9  // Their cryptography: elegant. Our modifications: bureaucracy-compatible.
10  // Original brilliance: theirs. Robert's Rules: ours. Bugs: definitely ours.
11  //
12  // Original Aleo/ProvableHQ code subject to Apache 2.0 https://www.apache.org/licenses/LICENSE-2.0
13  // All modifications and new work: CC0 1.0 Universal Public Domain Dedication.
14  // No rights reserved. No permission required. No warranty. No refunds.
15  //
16  // https://creativecommons.org/publicdomain/zero/1.0/
17  // SPDX-License-Identifier: CC0-1.0
18  
19  use super::*;
20  use crate::data::literal::cast_lossy::CastLossy;
21  
22  impl<E: Environment> Cast<Address<E>> for Boolean<E> {
23      /// Casts a `Boolean` to an `Address`.
24      #[inline]
25      fn cast(&self) -> Result<Address<E>> {
26          Ok(self.cast_lossy())
27      }
28  }
29  
30  impl<E: Environment> Cast<Boolean<E>> for Boolean<E> {
31      /// Casts a `Boolean` to a `Boolean`.
32      #[inline]
33      fn cast(&self) -> Result<Boolean<E>> {
34          Ok(self.cast_lossy())
35      }
36  }
37  
38  impl<E: Environment> Cast<Field<E>> for Boolean<E> {
39      /// Casts a `Boolean` to a `Field`.
40      #[inline]
41      fn cast(&self) -> Result<Field<E>> {
42          Ok(self.cast_lossy())
43      }
44  }
45  
46  impl<E: Environment> Cast<Group<E>> for Boolean<E> {
47      /// Casts a `Boolean` to a `Group`.
48      #[inline]
49      fn cast(&self) -> Result<Group<E>> {
50          Ok(self.cast_lossy())
51      }
52  }
53  
54  impl<E: Environment, I: IntegerType> Cast<Integer<E, I>> for Boolean<E> {
55      /// Casts a `Boolean` to an `Integer`.
56      #[inline]
57      fn cast(&self) -> Result<Integer<E, I>> {
58          match **self {
59              true => Ok(Integer::one()),
60              false => Ok(Integer::zero()),
61          }
62      }
63  }
64  
65  impl<E: Environment> Cast<Scalar<E>> for Boolean<E> {
66      /// Casts a `Boolean` to a `Scalar`.
67      #[inline]
68      fn cast(&self) -> Result<Scalar<E>> {
69          Ok(self.cast_lossy())
70      }
71  }