@@ -11,6 +11,7 @@ enum Path {
11
11
None ,
12
12
Instance ( syn:: Ident , syn:: PathSegment ) ,
13
13
Rename ( syn:: PathSegment ) ,
14
+ Protocol ( syn:: Path ) ,
14
15
}
15
16
16
17
#[ derive( Default ) ]
@@ -36,6 +37,22 @@ impl FunctionAttrs {
36
37
out. instance = true ;
37
38
} else if ident == "keep" {
38
39
out. keep = true ;
40
+ } else if ident == "protocol" {
41
+ input. parse :: < Token ! [ =] > ( ) ?;
42
+ let protocol: syn:: Path = input. parse ( ) ?;
43
+ out. path = Path :: Protocol ( if let Some ( protocol) = protocol. get_ident ( ) {
44
+ syn:: Path {
45
+ leading_colon : None ,
46
+ segments : [ "rune" , "runtime" , "Protocol" ]
47
+ . into_iter ( )
48
+ . map ( |i| syn:: Ident :: new ( i, protocol. span ( ) ) )
49
+ . chain ( Some ( protocol. clone ( ) ) )
50
+ . map ( syn:: PathSegment :: from)
51
+ . collect ( ) ,
52
+ }
53
+ } else {
54
+ protocol
55
+ } )
39
56
} else if ident == "path" {
40
57
input. parse :: < Token ! [ =] > ( ) ?;
41
58
@@ -55,12 +72,18 @@ impl FunctionAttrs {
55
72
let mut it = path. segments . into_iter ( ) ;
56
73
57
74
let Some ( first) = it. next ( ) else {
58
- return Err ( syn:: Error :: new ( input. span ( ) , "Expected at least one path segment" ) ) ;
75
+ return Err ( syn:: Error :: new (
76
+ input. span ( ) ,
77
+ "Expected at least one path segment" ,
78
+ ) ) ;
59
79
} ;
60
80
61
81
if let Some ( second) = it. next ( ) {
62
82
let syn:: PathArguments :: None = & first. arguments else {
63
- return Err ( syn:: Error :: new_spanned ( first. arguments , "Unsupported arguments" ) ) ;
83
+ return Err ( syn:: Error :: new_spanned (
84
+ first. arguments ,
85
+ "Unsupported arguments" ,
86
+ ) ) ;
64
87
} ;
65
88
66
89
out. path = Path :: Instance ( first. ident , second) ;
@@ -208,15 +231,24 @@ impl Function {
208
231
if instance {
209
232
self_type = None ;
210
233
211
- name = syn:: Expr :: Lit ( syn:: ExprLit {
212
- attrs : Vec :: new ( ) ,
213
- lit : syn:: Lit :: Str ( match & attrs. path {
214
- Path :: None => name_string. clone ( ) ,
215
- Path :: Rename ( last) | Path :: Instance ( _, last) => {
216
- syn:: LitStr :: new ( & last. ident . to_string ( ) , last. ident . span ( ) )
217
- }
218
- } ) ,
219
- } ) ;
234
+ name = ' out: {
235
+ syn:: Expr :: Lit ( syn:: ExprLit {
236
+ attrs : Vec :: new ( ) ,
237
+ lit : syn:: Lit :: Str ( match & attrs. path {
238
+ Path :: Protocol ( protocol) => {
239
+ break ' out syn:: Expr :: Path ( syn:: ExprPath {
240
+ attrs : Vec :: new ( ) ,
241
+ qself : None ,
242
+ path : protocol. clone ( ) ,
243
+ } )
244
+ }
245
+ Path :: None => name_string. clone ( ) ,
246
+ Path :: Rename ( last) | Path :: Instance ( _, last) => {
247
+ syn:: LitStr :: new ( & last. ident . to_string ( ) , last. ident . span ( ) )
248
+ }
249
+ } ) ,
250
+ } )
251
+ } ;
220
252
} else {
221
253
self_type = match & attrs. path {
222
254
Path :: Instance ( self_type, _) => Some ( self_type. clone ( ) ) ,
@@ -226,6 +258,11 @@ impl Function {
226
258
name = match & attrs. path {
227
259
Path :: None => expr_lit ( & self . sig . ident ) ,
228
260
Path :: Rename ( last) | Path :: Instance ( _, last) => expr_lit ( & last. ident ) ,
261
+ Path :: Protocol ( protocol) => syn:: Expr :: Path ( syn:: ExprPath {
262
+ attrs : Vec :: new ( ) ,
263
+ qself : None ,
264
+ path : protocol. clone ( ) ,
265
+ } ) ,
229
266
} ;
230
267
231
268
if !matches ! ( attrs. path, Path :: Instance ( ..) ) {
@@ -241,7 +278,7 @@ impl Function {
241
278
} ;
242
279
243
280
let arguments = match & attrs. path {
244
- Path :: None => Punctuated :: default ( ) ,
281
+ Path :: None | Path :: Protocol ( _ ) => Punctuated :: default ( ) ,
245
282
Path :: Rename ( last) | Path :: Instance ( _, last) => match & last. arguments {
246
283
syn:: PathArguments :: AngleBracketed ( arguments) => arguments. args . clone ( ) ,
247
284
syn:: PathArguments :: None => Punctuated :: default ( ) ,
0 commit comments