snarkvm_synthesizer_program/view/input/mod.rs
1// Copyright (c) 2019-2026 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 bytes;
17mod parse;
18
19use console::{
20 network::prelude::*,
21 program::{FinalizeType, Register},
22};
23
24/// An input statement defines an input argument to a view function, of the form
25/// `input {register} as {finalize_type};`.
26///
27/// View inputs reuse the finalize input shape because view bodies share the finalize
28/// command set and therefore the same plaintext-only register model.
29#[derive(Clone, PartialEq, Eq, Hash)]
30pub struct Input<N: Network> {
31 /// The input register.
32 register: Register<N>,
33 /// The input finalize type.
34 finalize_type: FinalizeType<N>,
35}
36
37impl<N: Network> Input<N> {
38 /// Returns the input register.
39 #[inline]
40 pub const fn register(&self) -> &Register<N> {
41 &self.register
42 }
43
44 /// Returns the input finalize type.
45 #[inline]
46 pub const fn finalize_type(&self) -> &FinalizeType<N> {
47 &self.finalize_type
48 }
49}
50
51impl<N: Network> TypeName for Input<N> {
52 /// Returns the type name as a string.
53 #[inline]
54 fn type_name() -> &'static str {
55 "input"
56 }
57}
58
59impl<N: Network> Ord for Input<N> {
60 /// Ordering is determined by the register (the finalize type is ignored).
61 fn cmp(&self, other: &Self) -> Ordering {
62 self.register().cmp(other.register())
63 }
64}
65
66impl<N: Network> PartialOrd for Input<N> {
67 /// Ordering is determined by the register (the finalize type is ignored).
68 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
69 Some(self.cmp(other))
70 }
71}