snarkvm_console_program/data/literal/cast/identifier.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
16use super::*;
17
18impl<N: Network> Cast<Address<N>> for IdentifierLiteral<N> {
19 /// Casts an `IdentifierLiteral` to an `Address`.
20 #[inline]
21 fn cast(&self) -> Result<Address<N>> {
22 self.to_field()?.cast()
23 }
24}
25
26impl<N: Network> Cast<Boolean<N>> for IdentifierLiteral<N> {
27 /// Casts an `IdentifierLiteral` to a `Boolean`.
28 ///
29 /// Note: This cast always fails because valid identifier literals start with
30 /// a letter (first byte >= 0x41), which cannot represent a boolean field value
31 /// (0 or 1). This implementation exists for uniformity with the `impl_cast_body!`
32 /// macro used by all literal types.
33 #[inline]
34 fn cast(&self) -> Result<Boolean<N>> {
35 self.to_field()?.cast()
36 }
37}
38
39impl<N: Network> Cast<Field<N>> for IdentifierLiteral<N> {
40 /// Casts an `IdentifierLiteral` to a `Field`.
41 #[inline]
42 fn cast(&self) -> Result<Field<N>> {
43 self.to_field()
44 }
45}
46
47impl<N: Network> Cast<Group<N>> for IdentifierLiteral<N> {
48 /// Casts an `IdentifierLiteral` to a `Group`.
49 #[inline]
50 fn cast(&self) -> Result<Group<N>> {
51 self.to_field()?.cast()
52 }
53}
54
55impl<N: Network, I: IntegerType> Cast<Integer<N, I>> for IdentifierLiteral<N> {
56 /// Casts an `IdentifierLiteral` to an `Integer`.
57 #[inline]
58 fn cast(&self) -> Result<Integer<N, I>> {
59 self.to_field()?.cast()
60 }
61}
62
63impl<N: Network> Cast<Scalar<N>> for IdentifierLiteral<N> {
64 /// Casts an `IdentifierLiteral` to a `Scalar`.
65 #[inline]
66 fn cast(&self) -> Result<Scalar<N>> {
67 self.to_field()?.cast()
68 }
69}
70
71impl<N: Network> Cast<IdentifierLiteral<N>> for IdentifierLiteral<N> {
72 /// Casts an `IdentifierLiteral` to itself.
73 #[inline]
74 fn cast(&self) -> Result<IdentifierLiteral<N>> {
75 Ok(*self)
76 }
77}