snarkvm_circuit_program/data/value/
mod.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
16mod equal;
17mod find;
18mod to_bits;
19mod to_fields;
20
21use crate::{Access, Entry, Future, Plaintext, Record};
22use snarkvm_circuit_network::Aleo;
23use snarkvm_circuit_types::{Boolean, Field, environment::prelude::*};
24
25#[derive(Clone)]
26pub enum Value<A: Aleo> {
27    /// A plaintext value.
28    Plaintext(Plaintext<A>),
29    /// A record value.
30    Record(Record<A, Plaintext<A>>),
31    /// A future.
32    Future(Future<A>),
33}
34
35impl<A: Aleo> Inject for Value<A> {
36    type Primitive = console::Value<A::Network>;
37
38    /// Initializes a circuit of the given mode and value.
39    fn new(mode: Mode, value: Self::Primitive) -> Self {
40        match value {
41            console::Value::Plaintext(plaintext) => Value::Plaintext(Plaintext::new(mode, plaintext)),
42            console::Value::Record(record) => Value::Record(Record::new(Mode::Private, record)),
43            console::Value::Future(future) => Value::Future(Future::new(mode, future)),
44        }
45    }
46}
47
48impl<A: Aleo> Eject for Value<A> {
49    type Primitive = console::Value<A::Network>;
50
51    /// Ejects the mode of the circuit value.
52    fn eject_mode(&self) -> Mode {
53        match self {
54            Value::Plaintext(plaintext) => plaintext.eject_mode(),
55            Value::Record(record) => record.eject_mode(),
56            Value::Future(future) => future.eject_mode(),
57        }
58    }
59
60    /// Ejects the circuit value.
61    fn eject_value(&self) -> Self::Primitive {
62        match self {
63            Value::Plaintext(plaintext) => console::Value::Plaintext(plaintext.eject_value()),
64            Value::Record(record) => console::Value::Record(record.eject_value()),
65            Value::Future(future) => console::Value::Future(future.eject_value()),
66        }
67    }
68}