-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathmod.rs
More file actions
89 lines (75 loc) · 2.83 KB
/
mod.rs
File metadata and controls
89 lines (75 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright (c) 2019-2025 Provable Inc.
// This file is part of the snarkVM library.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
mod equal;
mod find;
mod to_bits;
mod to_fields;
use crate::{Access, Entry, Future, Plaintext, Record};
use snarkvm_circuit_network::Aleo;
use snarkvm_circuit_types::{Boolean, Field, environment::prelude::*};
#[derive(Clone)]
pub enum Value<A: Aleo> {
/// A plaintext value.
Plaintext(Plaintext<A>),
/// A record value.
Record(Record<A, Plaintext<A>>),
/// A future.
Future(Future<A>),
}
impl<A: Aleo> Inject for Value<A> {
type Primitive = console::Value<A::Network>;
/// Initializes a circuit of the given mode and value.
fn new(mode: Mode, value: Self::Primitive) -> Self {
match value {
console::Value::Plaintext(plaintext) => Value::Plaintext(Plaintext::new(mode, plaintext)),
console::Value::Record(record) => Value::Record(Record::new(Mode::Private, record)),
console::Value::Future(future) => Value::Future(Future::new(mode, future)),
}
}
}
impl<A: Aleo> Eject for Value<A> {
type Primitive = console::Value<A::Network>;
/// Ejects the mode of the circuit value.
fn eject_mode(&self) -> Mode {
match self {
Value::Plaintext(plaintext) => plaintext.eject_mode(),
Value::Record(record) => record.eject_mode(),
Value::Future(future) => future.eject_mode(),
}
}
/// Ejects the circuit value.
fn eject_value(&self) -> Self::Primitive {
match self {
Value::Plaintext(plaintext) => console::Value::Plaintext(plaintext.eject_value()),
Value::Record(record) => console::Value::Record(record.eject_value()),
Value::Future(future) => console::Value::Future(future.eject_value()),
}
}
}
impl<A: Aleo> From<Plaintext<A>> for Value<A> {
/// Initializes the value from a plaintext.
fn from(plaintext: Plaintext<A>) -> Self {
Self::Plaintext(plaintext)
}
}
impl<A: Aleo> From<Record<A, Plaintext<A>>> for Value<A> {
/// Initializes the value from a record.
fn from(record: Record<A, Plaintext<A>>) -> Self {
Self::Record(record)
}
}
impl<A: Aleo> From<Future<A>> for Value<A> {
/// Initializes the value from a future.
fn from(future: Future<A>) -> Self {
Self::Future(future)
}
}