snarkvm_console_types_integers/
lib.rs1#![cfg_attr(test, allow(clippy::assertions_on_result_states))]
17#![warn(clippy::cast_possible_truncation)]
18
19mod arithmetic;
20mod bitwise;
21mod bytes;
22mod compare;
23mod from_bits;
24mod from_field;
25mod from_field_lossy;
26mod from_fields;
27mod one;
28mod parse;
29mod random;
30mod serialize;
31mod size_in_bits;
32mod size_in_bytes;
33mod to_bits;
34mod to_field;
35mod to_fields;
36mod to_scalar;
37mod zero;
38
39pub use snarkvm_console_network_environment::prelude::*;
40pub use snarkvm_console_types_boolean::Boolean;
41pub use snarkvm_console_types_field::Field;
42pub use snarkvm_console_types_scalar::Scalar;
43
44use core::marker::PhantomData;
45
46pub type I8<E> = Integer<E, i8>;
47pub type I16<E> = Integer<E, i16>;
48pub type I32<E> = Integer<E, i32>;
49pub type I64<E> = Integer<E, i64>;
50pub type I128<E> = Integer<E, i128>;
51
52pub type U8<E> = Integer<E, u8>;
53pub type U16<E> = Integer<E, u16>;
54pub type U32<E> = Integer<E, u32>;
55pub type U64<E> = Integer<E, u64>;
56pub type U128<E> = Integer<E, u128>;
57
58#[derive(Copy, Clone, PartialEq, Eq, Hash)]
59pub struct Integer<E: Environment, I: IntegerType> {
60 integer: I,
62 _phantom: PhantomData<E>,
64}
65
66impl<E: Environment, I: IntegerType> IntegerTrait<I, U8<E>, U16<E>, U32<E>> for Integer<E, I> {}
67
68impl<E: Environment, I: IntegerType> IntegerCore<I> for Integer<E, I> {}
69
70impl<E: Environment, I: IntegerType> Visibility for Integer<E, I> {
71 type Boolean = Boolean<E>;
72
73 fn size_in_fields(&self) -> Result<u16> {
75 Ok(1)
76 }
77}
78
79impl<E: Environment, I: IntegerType> Integer<E, I> {
80 pub const MAX: Self = Self::new(I::MAX);
81 pub const MIN: Self = Self::new(I::MIN);
82
83 pub const fn new(integer: I) -> Self {
85 Self { integer, _phantom: PhantomData }
86 }
87}
88
89impl<E: Environment, I: IntegerType> TypeName for Integer<E, I> {
90 #[inline]
92 fn type_name() -> &'static str {
93 I::type_name()
94 }
95}
96
97impl<E: Environment, I: IntegerType> Deref for Integer<E, I> {
98 type Target = I;
99
100 #[inline]
101 fn deref(&self) -> &Self::Target {
102 &self.integer
103 }
104}