Skip to main content

snarkvm_circuit_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<E: Environment> Cast<Address<E>> for IdentifierLiteral<E> {
19    /// Casts an `IdentifierLiteral` to an `Address`.
20    #[inline]
21    fn cast(&self) -> Address<E> {
22        self.to_field().cast()
23    }
24}
25
26impl<E: Environment> Cast<Boolean<E>> for IdentifierLiteral<E> {
27    /// Casts an `IdentifierLiteral` to a `Boolean`.
28    ///
29    /// Note: This cast always fails because valid identifier literals cannot map
30    /// to boolean values (0x00 or 0x01). The byte 0x00 is null and 0x01 (SOH) is
31    /// not a valid identifier character. This implementation exists for uniformity
32    /// with the `impl_cast_body!` macro used by all literal types.
33    #[inline]
34    fn cast(&self) -> Boolean<E> {
35        self.to_field().cast()
36    }
37}
38
39impl<E: Environment> Cast<Field<E>> for IdentifierLiteral<E> {
40    /// Casts an `IdentifierLiteral` to a `Field`.
41    #[inline]
42    fn cast(&self) -> Field<E> {
43        self.to_field()
44    }
45}
46
47impl<E: Environment> Cast<Group<E>> for IdentifierLiteral<E> {
48    /// Casts an `IdentifierLiteral` to a `Group`.
49    #[inline]
50    fn cast(&self) -> Group<E> {
51        self.to_field().cast()
52    }
53}
54
55impl<E: Environment, I: IntegerType> Cast<Integer<E, I>> for IdentifierLiteral<E> {
56    /// Casts an `IdentifierLiteral` to an `Integer`.
57    #[inline]
58    fn cast(&self) -> Integer<E, I> {
59        self.to_field().cast()
60    }
61}
62
63impl<E: Environment> Cast<Scalar<E>> for IdentifierLiteral<E> {
64    /// Casts an `IdentifierLiteral` to a `Scalar`.
65    #[inline]
66    fn cast(&self) -> Scalar<E> {
67        self.to_field().cast()
68    }
69}
70
71impl<E: Environment> Cast<IdentifierLiteral<E>> for IdentifierLiteral<E> {
72    /// Casts an `IdentifierLiteral` to itself.
73    #[inline]
74    fn cast(&self) -> IdentifierLiteral<E> {
75        self.clone()
76    }
77}