snarkvm_circuit_program/data/value/
mod.rs

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