1
+ //! Procedural macros for the `starknet` crate. This crate provides macros that help make defining
2
+ //! certain compile-time constants easier.
3
+
4
+ #![ deny( missing_docs) ]
5
+
1
6
use proc_macro:: TokenStream ;
2
7
use starknet_core:: {
3
8
types:: Felt ,
4
9
utils:: { cairo_short_string_to_felt, get_selector_from_name} ,
5
10
} ;
6
11
use syn:: { parse_macro_input, LitStr } ;
7
12
13
+ /// Defines a compile-time constant for a entrypoint selector of a Starknet contract.
8
14
#[ proc_macro]
9
15
pub fn selector ( input : TokenStream ) -> TokenStream {
10
16
let input = parse_macro_input ! ( input as LitStr ) ;
@@ -26,6 +32,7 @@ pub fn selector(input: TokenStream) -> TokenStream {
26
32
. unwrap ( )
27
33
}
28
34
35
+ /// Defines a compile-time constant for a Cairo short string encoding from a human-readable string.
29
36
#[ proc_macro]
30
37
pub fn short_string ( input : TokenStream ) -> TokenStream {
31
38
let input = parse_macro_input ! ( input as LitStr ) ;
@@ -47,6 +54,8 @@ pub fn short_string(input: TokenStream) -> TokenStream {
47
54
. unwrap ( )
48
55
}
49
56
57
+ /// Defines a compile-time constant for a field element from its decimal or hexadecimal
58
+ /// representation.
50
59
#[ proc_macro]
51
60
pub fn felt ( input : TokenStream ) -> TokenStream {
52
61
let input = parse_macro_input ! ( input as LitStr ) ;
@@ -73,6 +82,7 @@ pub fn felt(input: TokenStream) -> TokenStream {
73
82
. unwrap ( )
74
83
}
75
84
85
+ /// Defines a compile-time constant for a field element from its decimal representation.
76
86
#[ proc_macro]
77
87
pub fn felt_dec ( input : TokenStream ) -> TokenStream {
78
88
let input = parse_macro_input ! ( input as LitStr ) ;
@@ -94,6 +104,7 @@ pub fn felt_dec(input: TokenStream) -> TokenStream {
94
104
. unwrap ( )
95
105
}
96
106
107
+ /// Defines a compile-time constant for a field element from its hexadecimal representation.
97
108
#[ proc_macro]
98
109
pub fn felt_hex ( input : TokenStream ) -> TokenStream {
99
110
let input = parse_macro_input ! ( input as LitStr ) ;
@@ -116,7 +127,7 @@ pub fn felt_hex(input: TokenStream) -> TokenStream {
116
127
}
117
128
118
129
#[ cfg( feature = "use_imported_type" ) ]
119
- fn field_element_path ( ) -> & ' static str {
130
+ const fn field_element_path ( ) -> & ' static str {
120
131
"Felt"
121
132
}
122
133
0 commit comments