3
3
use super :: { EntityExt , MemberExt , ParameterExt , ParameterSliceExt } ;
4
4
use crate :: code_gen_util:: TypeContext ;
5
5
use crate :: cs_attributes:: CsEncodedReturn ;
6
- use slicec:: grammar:: { AttributeFunctions , Contained , Operation } ;
6
+ use slicec:: grammar:: { AttributeFunctions , Operation } ;
7
7
8
8
pub trait OperationExt {
9
9
/// Returns the format that classes should be encoded with.
10
10
fn get_class_format ( & self , is_dispatch : bool ) -> & str ;
11
11
12
- /// The operation return task.
13
- fn return_task ( & self , is_dispatch : bool ) -> String ;
12
+ fn invocation_return_task ( & self , task_type : & str ) -> String ;
13
+ fn dispatch_return_task ( & self ) -> String ;
14
14
}
15
15
16
16
impl OperationExt for Operation {
@@ -25,50 +25,35 @@ impl OperationExt for Operation {
25
25
}
26
26
}
27
27
28
- fn return_task ( & self , is_dispatch : bool ) -> String {
28
+ fn invocation_return_task ( & self , task_type : & str ) -> String {
29
+ let namespace = & self . namespace ( ) ;
30
+ let return_type = match self . return_members ( ) . as_slice ( ) {
31
+ [ ] => "" . to_owned ( ) ,
32
+ members => format ! ( "<{}>" , members. to_tuple_type( namespace, TypeContext :: IncomingParam ) ) ,
33
+ } ;
34
+ format ! ( "global::System.Threading.Tasks.{task_type}{return_type}" )
35
+ }
36
+
37
+ fn dispatch_return_task ( & self ) -> String {
29
38
let return_members = self . return_members ( ) ;
30
39
if return_members. is_empty ( ) {
31
- if is_dispatch {
32
- "global::System.Threading.Tasks.ValueTask" . to_owned ( )
33
- } else {
34
- "global::System.Threading.Tasks.Task" . to_owned ( )
35
- }
40
+ "global::System.Threading.Tasks.ValueTask" . to_owned ( )
36
41
} else {
37
- let return_type = operation_return_type (
38
- self ,
39
- is_dispatch,
40
- if is_dispatch {
41
- TypeContext :: OutgoingParam
42
+ let namespace = self . namespace ( ) ;
43
+ let return_type = if self . has_attribute :: < CsEncodedReturn > ( ) {
44
+ if let Some ( stream_member) = self . streamed_return_member ( ) {
45
+ format ! (
46
+ "(global::System.IO.Pipelines.PipeReader Payload, {} {})" ,
47
+ stream_member. cs_type_string( & namespace, TypeContext :: OutgoingParam ) ,
48
+ stream_member. field_name( ) ,
49
+ )
42
50
} else {
43
- TypeContext :: IncomingParam
44
- } ,
45
- ) ;
46
- if is_dispatch {
47
- format ! ( "global::System.Threading.Tasks.ValueTask<{return_type}>" )
51
+ "global::System.IO.Pipelines.PipeReader" . to_owned ( )
52
+ }
48
53
} else {
49
- format ! ( "global::System.Threading.Tasks.Task<{return_type}>" )
50
- }
51
- }
52
- }
53
- }
54
-
55
- fn operation_return_type ( operation : & Operation , is_dispatch : bool , context : TypeContext ) -> String {
56
- let namespace = operation. parent ( ) . namespace ( ) ;
57
- if is_dispatch && operation. has_attribute :: < CsEncodedReturn > ( ) {
58
- if let Some ( stream_member) = operation. streamed_return_member ( ) {
59
- format ! (
60
- "(global::System.IO.Pipelines.PipeReader Payload, {} {})" ,
61
- stream_member. cs_type_string( & namespace, context) ,
62
- stream_member. field_name( ) ,
63
- )
64
- } else {
65
- "global::System.IO.Pipelines.PipeReader" . to_owned ( )
66
- }
67
- } else {
68
- match operation. return_members ( ) . as_slice ( ) {
69
- [ ] => "void" . to_owned ( ) ,
70
- [ member] => member. cs_type_string ( & namespace, context) ,
71
- members => members. to_tuple_type ( & namespace, context) ,
54
+ return_members. to_tuple_type ( & namespace, TypeContext :: OutgoingParam )
55
+ } ;
56
+ format ! ( "global::System.Threading.Tasks.ValueTask<{return_type}>" )
72
57
}
73
58
}
74
59
}
0 commit comments