11//! Component-model guest export support for workflow crates.
2-
3- #![ allow( missing_docs) ]
4-
2+ //!
3+ //! Everything in this module is internal SDK/component glue.
54use crate :: {
65 BaseWorkflowContext ,
76 runtime:: {
@@ -74,8 +73,8 @@ impl<T: StaticWorkflowComponent> wit_guest::Guest for ExportedComponent<T> {
7473 initialize_workflow : decode_proto ( init. initialize_workflow ) ,
7574 } ;
7675 let workflow_type = init. initialize_workflow . workflow_type . clone ( ) ;
77- let instance = T :: instantiate_workflow ( & workflow_type , init , host )
78- . map_err ( convert_failure_to_wit_box ) ?;
76+ let instance =
77+ T :: instantiate_workflow ( & workflow_type , init , host ) . map_err ( |e| e . encode_to_vec ( ) ) ?;
7978 Ok ( wit_guest:: WorkflowInstance :: new ( ExportedWorkflowInstance (
8079 RefCell :: new ( instance) ,
8180 ) ) )
@@ -106,20 +105,18 @@ impl wit_guest::GuestWorkflowInstance for ExportedWorkflowInstance {
106105 wit_types:: QueryResponse {
107106 response : response
108107 . result
109- . map ( encode_proto )
110- . map_err ( encode_proto ) ,
108+ . map ( |e| e . encode_to_vec ( ) )
109+ . map_err ( |e| e . encode_to_vec ( ) ) ,
111110 } ,
112111 )
113112 }
114113 ActivationJobResult :: UpdateRejected ( failure) => {
115- wit_types:: ActivationJobResult :: UpdateRejected (
116- convert_failure_to_wit_box ( failure) ,
117- )
114+ wit_types:: ActivationJobResult :: UpdateRejected ( failure. encode_to_vec ( ) )
118115 }
119116 } )
120117 . collect ( ) ,
121118 } )
122- . map_err ( convert_failure_to_wit_box )
119+ . map_err ( |e| e . encode_to_vec ( ) )
123120 }
124121
125122 fn poll_routine (
@@ -140,28 +137,28 @@ impl wit_guest::GuestWorkflowInstance for ExportedWorkflowInstance {
140137 MainRoutineCompletion :: TaskFailed ( task_failure) => {
141138 wit_types:: MainRoutineCompletion :: TaskFailed (
142139 wit_types:: TaskFailure {
143- failure : convert_failure_to_wit_box ( task_failure. failure ) ,
140+ failure : task_failure. failure . encode_to_vec ( ) ,
144141 force_cause : task_failure. force_cause ,
145142 } ,
146143 )
147144 }
148145 MainRoutineCompletion :: Terminal ( outcome) => {
149146 wit_types:: MainRoutineCompletion :: Terminal ( match * outcome {
150147 TerminalOutcome :: Completed ( payload) => {
151- wit_types:: TerminalOutcome :: Completed ( encode_proto ( payload) )
148+ wit_types:: TerminalOutcome :: Completed (
149+ payload. encode_to_vec ( ) ,
150+ )
152151 }
153152 TerminalOutcome :: Failed ( failure) => {
154- wit_types:: TerminalOutcome :: Failed (
155- convert_failure_to_wit_box ( failure) ,
156- )
153+ wit_types:: TerminalOutcome :: Failed ( failure. encode_to_vec ( ) )
157154 }
158155 TerminalOutcome :: Cancelled => {
159156 wit_types:: TerminalOutcome :: Cancelled
160157 }
161158 TerminalOutcome :: ContinueAsNew ( req) => {
162- wit_types:: TerminalOutcome :: ContinueAsNew ( encode_proto (
163- * req,
164- ) )
159+ wit_types:: TerminalOutcome :: ContinueAsNew (
160+ req. encode_to_vec ( ) ,
161+ )
165162 }
166163 } )
167164 }
@@ -170,9 +167,9 @@ impl wit_guest::GuestWorkflowInstance for ExportedWorkflowInstance {
170167 RoutineCompletion :: Signal ( result) => {
171168 wit_types:: RoutineCompletion :: Signal ( match result {
172169 Ok ( ( ) ) => wit_types:: SignalRoutineCompletion :: Succeeded ,
173- Err ( failure) => wit_types :: SignalRoutineCompletion :: Failed (
174- convert_failure_to_wit_box ( failure) ,
175- ) ,
170+ Err ( failure) => {
171+ wit_types :: SignalRoutineCompletion :: Failed ( failure. encode_to_vec ( ) )
172+ }
176173 } )
177174 }
178175 RoutineCompletion :: Update ( completion) => {
@@ -183,7 +180,7 @@ impl wit_guest::GuestWorkflowInstance for ExportedWorkflowInstance {
183180 } => wit_types:: UpdateRoutineCompletion :: Completed (
184181 wit_types:: UpdateRoutineSuccess {
185182 protocol_instance_id,
186- value : encode_proto ( result) ,
183+ value : result. encode_to_vec ( ) ,
187184 } ,
188185 ) ,
189186 UpdateRoutineCompletion :: Rejected {
@@ -192,15 +189,15 @@ impl wit_guest::GuestWorkflowInstance for ExportedWorkflowInstance {
192189 } => wit_types:: UpdateRoutineCompletion :: Rejected (
193190 wit_types:: UpdateRoutineRejection {
194191 protocol_instance_id,
195- failure : convert_failure_to_wit_box ( failure) ,
192+ failure : failure. encode_to_vec ( ) ,
196193 } ,
197194 ) ,
198195 } )
199196 }
200197 } ) ,
201198 made_progress : result. made_progress ,
202199 } )
203- . map_err ( convert_failure_to_wit_box )
200+ . map_err ( |e| e . encode_to_vec ( ) )
204201 }
205202}
206203
@@ -237,18 +234,10 @@ impl WorkflowHost for ImportedWorkflowHost {
237234 }
238235
239236 fn push_command ( & self , command : WorkflowCommand ) {
240- wit_host:: push_command ( & encode_proto ( command) ) ;
237+ wit_host:: push_command ( & command. encode_to_vec ( ) ) ;
241238 }
242239}
243240
244- fn convert_failure_to_wit_box ( failure : WorkflowFailure ) -> wit_types:: Failure {
245- encode_proto ( * failure)
246- }
247-
248- fn encode_proto < M : Message > ( message : M ) -> Vec < u8 > {
249- message. encode_to_vec ( )
250- }
251-
252241fn decode_proto < M : Message + prost:: Name + Default > ( bytes : Vec < u8 > ) -> M {
253242 M :: decode ( bytes. as_slice ( ) ) . unwrap_or_else ( |err| {
254243 let n = M :: NAME ;
0 commit comments