Re-sync with internal repository
[hiphop-php.git] / third-party / thrift / src / thrift / compiler / test / fixtures / no-legacy-apis / gen-rust / lib.rs
blob12a35754de5b992e37ac56c9c46a1b8074de3451
1 // @generated by Thrift for src/module.thrift
2 // This file is probably not the place you want to edit!
4 #![recursion_limit = "100000000"]
5 #![allow(non_camel_case_types, non_snake_case, non_upper_case_globals, unused_crate_dependencies, clippy::type_complexity)]
7 pub use self::errors::*;
8 pub use self::types::*;
10 pub mod types;
12 #[doc(hidden)]
13 pub mod dependencies {
14     pub use thrift as thrift;
17 pub mod services {
18     pub mod my_service {
19         #[derive(Clone, Debug)]
20         pub enum QueryExn {
21             #[doc(hidden)]
22             Success(crate::types::MyStruct),
23             ApplicationException(::fbthrift::ApplicationException),
24         }
26         impl ::std::convert::From<::fbthrift::ApplicationException> for QueryExn {
27             fn from(exn: ::fbthrift::ApplicationException) -> Self {
28                 QueryExn::ApplicationException(exn)
29             }
30         }
32         impl ::fbthrift::ExceptionInfo for QueryExn {
33             fn exn_name(&self) -> &'static str {
34                 match self {
35                     QueryExn::Success(_) => panic!("ExceptionInfo::exn_name called on Success"),
36                     QueryExn::ApplicationException(aexn) => aexn.exn_name(),
37                 }
38             }
40             fn exn_value(&self) -> String {
41                 match self {
42                     QueryExn::Success(_) => panic!("ExceptionInfo::exn_value called on Success"),
43                     QueryExn::ApplicationException(aexn) => aexn.exn_value(),
44                 }
45             }
47             fn exn_is_declared(&self) -> bool {
48                 match self {
49                     QueryExn::Success(_) => panic!("ExceptionInfo::exn_is_declared called on Success"),
50                     QueryExn::ApplicationException(aexn) => aexn.exn_is_declared(),
51                 }
52             }
53         }
55         impl ::fbthrift::ResultInfo for QueryExn {
56             fn result_type(&self) -> ::fbthrift::ResultType {
57                 match self {
58                     QueryExn::Success(_) => ::fbthrift::ResultType::Return,
59                     QueryExn::ApplicationException(_aexn) => ::fbthrift::ResultType::Exception,
60                 }
61             }
62         }
64         impl ::fbthrift::GetTType for QueryExn {
65             const TTYPE: ::fbthrift::TType = ::fbthrift::TType::Struct;
66         }
68         impl<P> ::fbthrift::Serialize<P> for QueryExn
69         where
70             P: ::fbthrift::ProtocolWriter,
71         {
72             fn write(&self, p: &mut P) {
73                 if let QueryExn::ApplicationException(aexn) = self {
74                     return aexn.write(p);
75                 }
76                 p.write_struct_begin("Query");
77                 match self {
78                     QueryExn::Success(inner) => {
79                         p.write_field_begin(
80                             "Success",
81                             ::fbthrift::TType::Struct,
82                             0i16,
83                         );
84                         inner.write(p);
85                         p.write_field_end();
86                     }
87                     QueryExn::ApplicationException(_aexn) => unreachable!(),
88                 }
89                 p.write_field_stop();
90                 p.write_struct_end();
91             }
92         }
94         impl<P> ::fbthrift::Deserialize<P> for QueryExn
95         where
96             P: ::fbthrift::ProtocolReader,
97         {
98             fn read(p: &mut P) -> ::anyhow::Result<Self> {
99                 static RETURNS: &[::fbthrift::Field] = &[
100                     ::fbthrift::Field::new("Success", ::fbthrift::TType::Struct, 0),
101                 ];
102                 let _ = p.read_struct_begin(|_| ())?;
103                 let mut once = false;
104                 let mut alt = ::std::option::Option::None;
105                 loop {
106                     let (_, fty, fid) = p.read_field_begin(|_| (), RETURNS)?;
107                     match ((fty, fid as ::std::primitive::i32), once) {
108                         ((::fbthrift::TType::Stop, _), _) => {
109                             p.read_field_end()?;
110                             break;
111                         }
112                         ((::fbthrift::TType::Struct, 0i32), false) => {
113                             once = true;
114                             alt = ::std::option::Option::Some(QueryExn::Success(::fbthrift::Deserialize::read(p)?));
115                         }
116                         ((ty, _id), false) => p.skip(ty)?,
117                         ((badty, badid), true) => return ::std::result::Result::Err(::std::convert::From::from(
118                             ::fbthrift::ApplicationException::new(
119                                 ::fbthrift::ApplicationExceptionErrorCode::ProtocolError,
120                                 format!(
121                                     "unwanted extra union {} field ty {:?} id {}",
122                                     "QueryExn",
123                                     badty,
124                                     badid,
125                                 ),
126                             )
127                         )),
128                     }
129                     p.read_field_end()?;
130                 }
131                 p.read_struct_end()?;
132                 alt.ok_or_else(||
133                     ::fbthrift::ApplicationException::new(
134                         ::fbthrift::ApplicationExceptionErrorCode::MissingResult,
135                         format!("Empty union {}", "QueryExn"),
136                     )
137                     .into(),
138                 )
139             }
140         }
141     }
144 /// Client implementation for each service in `module`.
145 pub mod client {
147     pub struct MyServiceImpl<P, T, S = ::fbthrift::NoopSpawner> {
148         transport: T,
149         _phantom: ::std::marker::PhantomData<fn() -> (P, S)>,
150     }
152     impl<P, T, S> MyServiceImpl<P, T, S>
153     where
154         P: ::fbthrift::Protocol,
155         T: ::fbthrift::Transport,
156         P::Frame: ::fbthrift::Framing<DecBuf = ::fbthrift::FramingDecoded<T>>,
157         ::fbthrift::ProtocolEncoded<P>: ::fbthrift::BufMutExt<Final = ::fbthrift::FramingEncodedFinal<T>>,
158         P::Deserializer: ::std::marker::Send,
159         S: ::fbthrift::help::Spawner,
160     {
161         pub fn new(
162             transport: T,
163         ) -> Self {
164             Self {
165                 transport,
166                 _phantom: ::std::marker::PhantomData,
167             }
168         }
170         pub fn transport(&self) -> &T {
171             &self.transport
172         }
175         fn _query_impl(
176             &self,
177             arg_u: &crate::types::MyUnion,
178             rpc_options: T::RpcOptions,
179         ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<crate::types::MyStruct, crate::errors::my_service::QueryError>> {
180             use ::const_cstr::const_cstr;
181             use ::tracing::Instrument as _;
182             use ::futures::FutureExt as _;
184             const_cstr! {
185                 SERVICE_NAME = "MyService";
186                 METHOD_NAME = "MyService.query";
187             }
188             let args = self::Args_MyService_query {
189                 u: arg_u,
190                 _phantom: ::std::marker::PhantomData,
191             };
193             // need to do call setup outside of async block because T: Transport isn't Send
194             let request_env = match ::fbthrift::help::serialize_request_envelope::<P, _>("query", &args) {
195                 ::std::result::Result::Ok(res) => res,
196                 ::std::result::Result::Err(err) => return ::futures::future::err(err.into()).boxed(),
197             };
199             let call = self.transport()
200                 .call(SERVICE_NAME.as_cstr(), METHOD_NAME.as_cstr(), request_env, rpc_options)
201                 .instrument(::tracing::trace_span!("call", function = "MyService.query"));
203             async move {
204                 let reply_env = call.await?;
206                 let de = P::deserializer(reply_env);
207                 let (res, _de): (::std::result::Result<crate::services::my_service::QueryExn, _>, _) =
208                     ::fbthrift::help::async_deserialize_response_envelope::<P, _, S>(de).await?;
210                 match res {
211                     ::std::result::Result::Ok(exn) => ::std::convert::From::from(exn),
212                     ::std::result::Result::Err(aexn) =>
213                         ::std::result::Result::Err(crate::errors::my_service::QueryError::ApplicationException(aexn))
214                 }
215             }
216             .instrument(::tracing::info_span!("MyService.query"))
217             .boxed()
218         }
219     }
221     pub trait MyService: ::std::marker::Send {
222         fn query(
223             &self,
224             arg_u: &crate::types::MyUnion,
225         ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<crate::types::MyStruct, crate::errors::my_service::QueryError>>;
226     }
228     pub trait MyServiceExt<T>: MyService
229     where
230         T: ::fbthrift::Transport,
231     {
232         fn query_with_rpc_opts(
233             &self,
234             arg_u: &crate::types::MyUnion,
235             rpc_options: T::RpcOptions,
236         ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<crate::types::MyStruct, crate::errors::my_service::QueryError>>;
237     }
239     struct Args_MyService_query<'a> {
240         u: &'a crate::types::MyUnion,
241         _phantom: ::std::marker::PhantomData<&'a ()>,
242     }
244     impl<'a, P: ::fbthrift::ProtocolWriter> ::fbthrift::Serialize<P> for self::Args_MyService_query<'a> {
245         #[inline]
246         #[::tracing::instrument(skip_all, level = "trace", name = "serialize_args", fields(method = "MyService.query"))]
247         fn write(&self, p: &mut P) {
248             p.write_struct_begin("args");
249             p.write_field_begin("u", ::fbthrift::TType::Struct, 1i16);
250             ::fbthrift::Serialize::write(&self.u, p);
251             p.write_field_end();
252             p.write_field_stop();
253             p.write_struct_end();
254         }
255     }
257     impl<P, T, S> MyService for MyServiceImpl<P, T, S>
258     where
259         P: ::fbthrift::Protocol,
260         T: ::fbthrift::Transport,
261         P::Frame: ::fbthrift::Framing<DecBuf = ::fbthrift::FramingDecoded<T>>,
262         ::fbthrift::ProtocolEncoded<P>: ::fbthrift::BufMutExt<Final = ::fbthrift::FramingEncodedFinal<T>>,
263         P::Deserializer: ::std::marker::Send,
264         S: ::fbthrift::help::Spawner,
265     {
266         fn query(
267             &self,
268             arg_u: &crate::types::MyUnion,
269         ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<crate::types::MyStruct, crate::errors::my_service::QueryError>> {
270             let rpc_options = T::RpcOptions::default();
271             self._query_impl(
272                 arg_u,
273                 rpc_options,
274             )
275         }
276     }
278     impl<P, T, S> MyServiceExt<T> for MyServiceImpl<P, T, S>
279     where
280         P: ::fbthrift::Protocol,
281         T: ::fbthrift::Transport,
282         P::Frame: ::fbthrift::Framing<DecBuf = ::fbthrift::FramingDecoded<T>>,
283         ::fbthrift::ProtocolEncoded<P>: ::fbthrift::BufMutExt<Final = ::fbthrift::FramingEncodedFinal<T>>,
284         P::Deserializer: ::std::marker::Send,
285         S: ::fbthrift::help::Spawner,
286     {
287         fn query_with_rpc_opts(
288             &self,
289             arg_u: &crate::types::MyUnion,
290             rpc_options: T::RpcOptions,
291         ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<crate::types::MyStruct, crate::errors::my_service::QueryError>> {
292             self._query_impl(
293                 arg_u,
294                 rpc_options,
295             )
296         }
297     }
299     impl<'a, S> MyService for S
300     where
301         S: ::std::convert::AsRef<dyn MyService + 'a>,
302         S: ::std::marker::Send,
303     {
304         fn query(
305             &self,
306             arg_u: &crate::types::MyUnion,
307         ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<crate::types::MyStruct, crate::errors::my_service::QueryError>> {
308             self.as_ref().query(
309                 arg_u,
310             )
311         }
312     }
314     impl<'a, S, T> MyServiceExt<T> for S
315     where
316         S: ::std::convert::AsRef<dyn MyService + 'a>,
317         S: ::std::convert::AsRef<dyn MyServiceExt<T> + 'a>,
318         S: ::std::marker::Send,
319         T: ::fbthrift::Transport,
320     {
321         fn query_with_rpc_opts(
322             &self,
323             arg_u: &crate::types::MyUnion,
324             rpc_options: T::RpcOptions,
325         ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<crate::types::MyStruct, crate::errors::my_service::QueryError>> {
326             <Self as ::std::convert::AsRef<dyn MyServiceExt<T>>>::as_ref(self).query_with_rpc_opts(
327                 arg_u,
328                 rpc_options,
329             )
330         }
331     }
333     #[derive(Clone)]
334     pub struct make_MyService;
336     /// To be called by user directly setting up a client. Avoids
337     /// needing ClientFactory trait in scope, avoids unidiomatic
338     /// make_Trait name.
339     ///
340     /// ```
341     /// # const _: &str = stringify! {
342     /// use bgs::client::BuckGraphService;
343     ///
344     /// let protocol = BinaryProtocol::new();
345     /// let transport = HttpClient::new();
346     /// let client = <dyn BuckGraphService>::new(protocol, transport);
347     /// # };
348     /// ```
349     impl dyn MyService {
350         pub fn new<P, T>(
351             protocol: P,
352             transport: T,
353         ) -> ::std::sync::Arc<impl MyService + ::std::marker::Send + 'static>
354         where
355             P: ::fbthrift::Protocol<Frame = T>,
356             T: ::fbthrift::Transport,
357             P::Deserializer: ::std::marker::Send,
358         {
359             let spawner = ::fbthrift::help::NoopSpawner;
360             Self::with_spawner(protocol, transport, spawner)
361         }
363         pub fn with_spawner<P, T, S>(
364             protocol: P,
365             transport: T,
366             spawner: S,
367         ) -> ::std::sync::Arc<impl MyService + ::std::marker::Send + 'static>
368         where
369             P: ::fbthrift::Protocol<Frame = T>,
370             T: ::fbthrift::Transport,
371             P::Deserializer: ::std::marker::Send,
372             S: ::fbthrift::help::Spawner,
373         {
374             let _ = protocol;
375             let _ = spawner;
376             ::std::sync::Arc::new(MyServiceImpl::<P, T, S>::new(transport))
377         }
378     }
380     impl<T> dyn MyServiceExt<T>
381     where
382         T: ::fbthrift::Transport,
383     {
384         pub fn new<P>(
385             protocol: P,
386             transport: T,
387         ) -> ::std::sync::Arc<impl MyServiceExt<T> + ::std::marker::Send + 'static>
388         where
389             P: ::fbthrift::Protocol<Frame = T>,
390             P::Deserializer: ::std::marker::Send,
391         {
392             let spawner = ::fbthrift::help::NoopSpawner;
393             Self::with_spawner(protocol, transport, spawner)
394         }
396         pub fn with_spawner<P, S>(
397             protocol: P,
398             transport: T,
399             spawner: S,
400         ) -> ::std::sync::Arc<impl MyServiceExt<T> + ::std::marker::Send + 'static>
401         where
402             P: ::fbthrift::Protocol<Frame = T>,
403             P::Deserializer: ::std::marker::Send,
404             S: ::fbthrift::help::Spawner,
405         {
406             let _ = protocol;
407             let _ = spawner;
408             ::std::sync::Arc::new(MyServiceImpl::<P, T, S>::new(transport))
409         }
410     }
412     pub type MyServiceDynClient = <make_MyService as ::fbthrift::ClientFactory>::Api;
413     pub type MyServiceClient = ::std::sync::Arc<MyServiceDynClient>;
415     /// The same thing, but to be called from generic contexts where we are
416     /// working with a type parameter `C: ClientFactory` to produce clients.
417     impl ::fbthrift::ClientFactory for make_MyService {
418         type Api = dyn MyService + ::std::marker::Send + ::std::marker::Sync + 'static;
420         fn with_spawner<P, T, S>(protocol: P, transport: T, spawner: S) -> ::std::sync::Arc<Self::Api>
421         where
422             P: ::fbthrift::Protocol<Frame = T>,
423             T: ::fbthrift::Transport + ::std::marker::Sync,
424             P::Deserializer: ::std::marker::Send,
425             S: ::fbthrift::help::Spawner,
426         {
427             <dyn MyService>::with_spawner(protocol, transport, spawner)
428         }
429     }
433 /// Server definitions for `module`.
434 pub mod server {
435     #[::async_trait::async_trait]
436     pub trait MyService: ::std::marker::Send + ::std::marker::Sync + 'static {
437         async fn query(
438             &self,
439             _u: crate::types::MyUnion,
440         ) -> ::std::result::Result<
441     crate::types::MyStruct,
442     crate::services::my_service::QueryExn> {
443             ::std::result::Result::Err(crate::services::my_service::QueryExn::ApplicationException(
444                 ::fbthrift::ApplicationException::unimplemented_method(
445                     "MyService",
446                     "query",
447                 ),
448             ))
449         }
450     }
452     #[::async_trait::async_trait]
453     impl<T> MyService for ::std::boxed::Box<T>
454     where
455         T: MyService + Send + Sync + ?Sized,
456     {
457         async fn query(
458             &self,
459             u: crate::types::MyUnion,
460         ) -> ::std::result::Result<
461     crate::types::MyStruct,
462     crate::services::my_service::QueryExn> {
463             (**self).query(
464                 u, 
465             ).await
466         }
467     }
469     /// Processor for MyService's methods.
470     #[derive(Clone, Debug)]
471     pub struct MyServiceProcessor<P, H, R, RS> {
472         service: H,
473         supa: ::fbthrift::NullServiceProcessor<P, R, RS>,
474         _phantom: ::std::marker::PhantomData<(P, H, R, RS)>,
475     }
477     struct Args_MyService_query {
478         u: crate::types::MyUnion,
479     }
480     impl<P: ::fbthrift::ProtocolReader> ::fbthrift::Deserialize<P> for self::Args_MyService_query {
481         #[inline]
482         #[::tracing::instrument(skip_all, level = "trace", name = "deserialize_args", fields(method = "MyService.query"))]
483         fn read(p: &mut P) -> ::anyhow::Result<Self> {
484             static ARGS: &[::fbthrift::Field] = &[
485                 ::fbthrift::Field::new("u", ::fbthrift::TType::Struct, 1),
486             ];
487             let mut field_u = ::std::option::Option::None;
488             let _ = p.read_struct_begin(|_| ())?;
489             loop {
490                 let (_, fty, fid) = p.read_field_begin(|_| (), ARGS)?;
491                 match (fty, fid as ::std::primitive::i32) {
492                     (::fbthrift::TType::Stop, _) => break,
493                     (::fbthrift::TType::Struct, 1) => field_u = ::std::option::Option::Some(::fbthrift::Deserialize::read(p)?),
494                     (fty, _) => p.skip(fty)?,
495                 }
496                 p.read_field_end()?;
497             }
498             p.read_struct_end()?;
499             ::std::result::Result::Ok(Self {
500                 u: field_u.ok_or_else(|| ::anyhow::anyhow!("`{}` missing arg `{}`", "MyService.query", "u"))?,
501             })
502         }
503     }
506     impl<P, H, R, RS> MyServiceProcessor<P, H, R, RS>
507     where
508         P: ::fbthrift::Protocol + ::std::marker::Send + ::std::marker::Sync + 'static,
509         P::Deserializer: ::std::marker::Send,
510         H: MyService,
511         R: ::fbthrift::RequestContext<Name = ::std::ffi::CStr> + ::std::marker::Sync,
512         RS: ::fbthrift::ReplyState<P::Frame>,
513         <R as ::fbthrift::RequestContext>::ContextStack: ::fbthrift::ContextStack<Name = R::Name, Buffer = ::fbthrift::ProtocolDecoded<P>>
514             + ::std::marker::Send + ::std::marker::Sync,
515     {
516         pub fn new(service: H) -> Self {
517             Self {
518                 service,
519                 supa: ::fbthrift::NullServiceProcessor::new(),
520                 _phantom: ::std::marker::PhantomData,
521             }
522         }
524         pub fn into_inner(self) -> H {
525             self.service
526         }
528         #[::tracing::instrument(skip_all, fields(method = "MyService.query"))]
529         async fn handle_query<'a>(
530             &'a self,
531             p: &'a mut P::Deserializer,
532             req_ctxt: &R,
533             reply_state: ::std::sync::Arc<::std::sync::Mutex<RS>>,
534             _seqid: ::std::primitive::u32,
535         ) -> ::anyhow::Result<()> {
536             use ::const_cstr::const_cstr;
537             use ::tracing::Instrument as _;
538             use ::futures::FutureExt as _;
540             const_cstr! {
541                 SERVICE_NAME = "MyService";
542                 METHOD_NAME = "MyService.query";
543             }
544             let mut ctx_stack = req_ctxt.get_context_stack(
545                 SERVICE_NAME.as_cstr(),
546                 METHOD_NAME.as_cstr(),
547             )?;
548             ::fbthrift::ContextStack::pre_read(&mut ctx_stack)?;
549             let _args: self::Args_MyService_query = ::fbthrift::Deserialize::read(p)?;
550             ::fbthrift::ContextStack::on_read_data(&mut ctx_stack, &::fbthrift::SerializedMessage {
551                 protocol: P::PROTOCOL_ID,
552                 method_name: METHOD_NAME.as_cstr(),
553                 buffer: ::std::marker::PhantomData, // FIXME P::into_buffer(p).reset(),
554             })?;
555             ::fbthrift::ContextStack::post_read(&mut ctx_stack, 0)?;
557             let res = ::std::panic::AssertUnwindSafe(
558                 self.service.query(
559                     _args.u,
560                 )
561             )
562             .catch_unwind()
563             .instrument(::tracing::info_span!("service_handler", method = "MyService.query"))
564             .await;
566             // nested results - panic catch on the outside, method on the inside
567             let res = match res {
568                 ::std::result::Result::Ok(::std::result::Result::Ok(res)) => {
569                     ::tracing::info!(method = "MyService.query", "success");
570                     crate::services::my_service::QueryExn::Success(res)
571                 }
572                 ::std::result::Result::Ok(::std::result::Result::Err(crate::services::my_service::QueryExn::Success(_))) => {
573                     panic!(
574                         "{} attempted to return success via error",
575                         "query",
576                     )
577                 }
578                 ::std::result::Result::Ok(::std::result::Result::Err(exn)) => {
579                     ::tracing::error!(method = "MyService.query", exception = ?exn);
580                     exn
581                 }
582                 ::std::result::Result::Err(exn) => {
583                     let aexn = ::fbthrift::ApplicationException::handler_panic("MyService.query", exn);
584                     crate::services::my_service::QueryExn::ApplicationException(aexn)
585                 }
586             };
588             let env = ::fbthrift::help::serialize_result_envelope::<P, R, _>(
589                 "query",
590                 METHOD_NAME.as_cstr(),
591                 _seqid,
592                 req_ctxt,
593                 &mut ctx_stack,
594                 res
595             )?;
596             reply_state.lock().unwrap().send_reply(env);
597             Ok(())
598         }
599     }
601     #[::async_trait::async_trait]
602     impl<P, H, R, RS> ::fbthrift::ServiceProcessor<P> for MyServiceProcessor<P, H, R, RS>
603     where
604         P: ::fbthrift::Protocol + ::std::marker::Send + ::std::marker::Sync + 'static,
605         P::Deserializer: ::std::marker::Send,
606         H: MyService,
607         P::Frame: ::std::marker::Send + 'static,
608         R: ::fbthrift::RequestContext<Name = ::std::ffi::CStr> + ::std::marker::Send + ::std::marker::Sync + 'static,
609         <R as ::fbthrift::RequestContext>::ContextStack: ::fbthrift::ContextStack<Name = R::Name, Buffer = ::fbthrift::ProtocolDecoded<P>>
610             + ::std::marker::Send + ::std::marker::Sync + 'static,
611         RS: ::fbthrift::ReplyState<P::Frame> + ::std::marker::Send + ::std::marker::Sync + 'static
612     {
613         type RequestContext = R;
614         type ReplyState = RS;
616         #[inline]
617         fn method_idx(&self, name: &[::std::primitive::u8]) -> ::std::result::Result<::std::primitive::usize, ::fbthrift::ApplicationException> {
618             match name {
619                 b"query" => ::std::result::Result::Ok(0usize),
620                 _ => ::std::result::Result::Err(::fbthrift::ApplicationException::unknown_method()),
621             }
622         }
624         #[allow(clippy::match_single_binding)]
625         async fn handle_method(
626             &self,
627             idx: ::std::primitive::usize,
628             _p: &mut P::Deserializer,
629             _r: &R,
630             _reply_state: ::std::sync::Arc<::std::sync::Mutex<RS>>,
631             _seqid: ::std::primitive::u32,
632         ) -> ::anyhow::Result<()> {
633             match idx {
634                 0usize => {
635                     self.handle_query(_p, _r, _reply_state, _seqid).await
636                 }
637                 bad => panic!(
638                     "{}: unexpected method idx {}",
639                     "MyServiceProcessor",
640                     bad
641                 ),
642             }
643         }
645         #[allow(clippy::match_single_binding)]
646         #[inline]
647         fn create_interaction_idx(&self, name: &str) -> ::anyhow::Result<::std::primitive::usize> {
648             match name {
649                 _ => ::anyhow::bail!("Unknown interaction"),
650             }
651         }
653         #[allow(clippy::match_single_binding)]
654         fn handle_create_interaction(
655             &self,
656             idx: ::std::primitive::usize,
657         ) -> ::anyhow::Result<
658             ::std::sync::Arc<dyn ::fbthrift::ThriftService<P::Frame, Handler = (), RequestContext = Self::RequestContext, ReplyState = Self::ReplyState> + ::std::marker::Send + 'static>
659         > {
660             match idx {
661                 bad => panic!(
662                     "{}: unexpected method idx {}",
663                     "MyServiceProcessor",
664                     bad
665                 ),
666             }
667         }
668     }
670     #[::async_trait::async_trait]
671     impl<P, H, R, RS> ::fbthrift::ThriftService<P::Frame> for MyServiceProcessor<P, H, R, RS>
672     where
673         P: ::fbthrift::Protocol + ::std::marker::Send + ::std::marker::Sync + 'static,
674         P::Deserializer: ::std::marker::Send,
675         P::Frame: ::std::marker::Send + 'static,
676         H: MyService,
677         R: ::fbthrift::RequestContext<Name = ::std::ffi::CStr> + ::std::marker::Send + ::std::marker::Sync + 'static,
678         <R as ::fbthrift::RequestContext>::ContextStack: ::fbthrift::ContextStack<Name = R::Name, Buffer = ::fbthrift::ProtocolDecoded<P>>
679             + ::std::marker::Send + ::std::marker::Sync + 'static,
680         RS: ::fbthrift::ReplyState<P::Frame> + ::std::marker::Send + ::std::marker::Sync + 'static
681     {
682         type Handler = H;
683         type RequestContext = R;
684         type ReplyState = RS;
686         #[tracing::instrument(level="trace", skip_all, fields(service = "MyService"))]
687         async fn call(
688             &self,
689             req: ::fbthrift::ProtocolDecoded<P>,
690             req_ctxt: &R,
691             reply_state: ::std::sync::Arc<::std::sync::Mutex<RS>>,
692         ) -> ::anyhow::Result<()> {
693             use ::fbthrift::{BufExt as _, ProtocolReader as _, ServiceProcessor as _};
694             let mut p = P::deserializer(req);
695             let (idx, mty, seqid) = p.read_message_begin(|name| self.method_idx(name))?;
696             if mty != ::fbthrift::MessageType::Call {
697                 return ::std::result::Result::Err(::std::convert::From::from(::fbthrift::ApplicationException::new(
698                     ::fbthrift::ApplicationExceptionErrorCode::InvalidMessageType,
699                     format!("message type {:?} not handled", mty)
700                 )));
701             }
702             let idx = match idx {
703                 ::std::result::Result::Ok(idx) => idx,
704                 ::std::result::Result::Err(_) => {
705                     let cur = P::into_buffer(p).reset();
706                     return self.supa.call(cur, req_ctxt, reply_state).await;
707                 }
708             };
709             self.handle_method(idx, &mut p, req_ctxt, reply_state, seqid).await?;
710             p.read_message_end()?;
712             Ok(())
713         }
715         fn create_interaction(
716             &self,
717             name: &str,
718         ) -> ::anyhow::Result<
719             ::std::sync::Arc<dyn ::fbthrift::ThriftService<P::Frame, Handler = (), RequestContext = R, ReplyState = RS> + ::std::marker::Send + 'static>
720         > {
721             use ::fbthrift::{ServiceProcessor as _};
722             let idx = self.create_interaction_idx(name);
723             let idx = match idx {
724                 ::anyhow::Result::Ok(idx) => idx,
725                 ::anyhow::Result::Err(_) => {
726                     return self.supa.create_interaction(name);
727                 }
728             };
729             self.handle_create_interaction(idx)
730         }
731     }
733     /// Construct a new instance of a MyService service.
734     ///
735     /// This is called when a new instance of a Thrift service Processor
736     /// is needed for a particular Thrift protocol.
737     #[::tracing::instrument(level="debug", skip_all, fields(proto = ?proto))]
738     pub fn make_MyService_server<F, H, R, RS>(
739         proto: ::fbthrift::ProtocolID,
740         handler: H,
741     ) -> ::std::result::Result<::std::boxed::Box<dyn ::fbthrift::ThriftService<F, Handler = H, RequestContext = R, ReplyState = RS> + ::std::marker::Send + 'static>, ::fbthrift::ApplicationException>
742     where
743         F: ::fbthrift::Framing + ::std::marker::Send + ::std::marker::Sync + 'static,
744         H: MyService,
745         R: ::fbthrift::RequestContext<Name = ::std::ffi::CStr> + ::std::marker::Send + ::std::marker::Sync + 'static,
746         <R as ::fbthrift::RequestContext>::ContextStack: ::fbthrift::ContextStack<Name = R::Name, Buffer = F::DecBuf> + ::std::marker::Send + ::std::marker::Sync + 'static,
747         RS: ::fbthrift::ReplyState<F> + ::std::marker::Send + ::std::marker::Sync + 'static
748     {
749         match proto {
750             ::fbthrift::ProtocolID::BinaryProtocol => {
751                 ::std::result::Result::Ok(::std::boxed::Box::new(MyServiceProcessor::<::fbthrift::BinaryProtocol<F>, H, R, RS>::new(handler)))
752             }
753             ::fbthrift::ProtocolID::CompactProtocol => {
754                 ::std::result::Result::Ok(::std::boxed::Box::new(MyServiceProcessor::<::fbthrift::CompactProtocol<F>, H, R, RS>::new(handler)))
755             }
756             bad => {
757                 ::tracing::error!(method = "MyService.", invalid_protocol = ?bad);
758                 ::std::result::Result::Err(::fbthrift::ApplicationException::invalid_protocol(bad))
759             }
760         }
761     }
764 /// Client mocks. For every service, a struct mock::TheService that implements
765 /// client::TheService.
767 /// As an example of the generated API, for the following thrift service:
769 /// ```thrift
770 /// service MyService {
771 ///     FunctionResponse myFunction(
772 ///         1: FunctionRequest request,
773 ///     ) throws {
774 ///         1: StorageException s,
775 ///         2: NotFoundException n,
776 ///     ),
778 ///     // other functions
779 /// }
780 /// ```
782 /// we would end up with this mock object under crate::mock::MyService:
784 /// ```
785 /// # const _: &str = stringify! {
786 /// impl crate::client::MyService for MyService<'mock> {...}
788 /// pub struct MyService<'mock> {
789 ///     pub myFunction: myFunction<'mock>,
790 ///     // ...
791 /// }
793 /// impl dyn crate::client::MyService {
794 ///     pub fn mock<'mock>() -> MyService<'mock>;
795 /// }
797 /// impl myFunction<'mock> {
798 ///     // directly return the given success response
799 ///     pub fn ret(&self, value: FunctionResponse);
801 ///     // invoke closure to compute success response
802 ///     pub fn mock(
803 ///         &self,
804 ///         mock: impl FnMut(FunctionRequest) -> FunctionResponse + Send + Sync + 'mock,
805 ///     );
807 ///     // invoke closure to compute response
808 ///     pub fn mock_result(
809 ///         &self,
810 ///         mock: impl FnMut(FunctionRequest) -> Result<FunctionResponse, crate::services::MyService::MyFunctionExn> + Send + Sync + 'mock,
811 ///     );
813 ///     // return one of the function's declared exceptions
814 ///     pub fn throw<E>(&self, exception: E)
815 ///     where
816 ///         E: Clone + Into<crate::services::MyService::MyFunctionExn> + Send + Sync + 'mock;
817 /// }
819 /// impl From<StorageException> for MyFunctionExn {...}
820 /// impl From<NotFoundException> for MyFunctionExn {...}
821 /// # };
822 /// ```
824 /// The intended usage from a test would be:
826 /// ```
827 /// # const _: &str = stringify! {
828 /// use std::sync::Arc;
829 /// use thrift_if::client::MyService;
831 /// #[test]
832 /// fn test_my_client() {
833 ///     let mock = Arc::new(<dyn MyService>::mock());
835 ///     // directly return a success response
836 ///     let resp = FunctionResponse {...};
837 ///     mock.myFunction.ret(resp);
839 ///     // or give a closure to compute the success response
840 ///     mock.myFunction.mock(|request| FunctionResponse {...});
842 ///     // or throw one of the function's exceptions
843 ///     mock.myFunction.throw(StorageException::ItFailed);
845 ///     // or compute a Result (useful if your exceptions aren't Clone)
846 ///     mock.myFunction.mock_result(|request| Err(...));
848 ///     let out = do_the_thing(mock).wait().unwrap();
849 ///     assert!(out.what_i_expected());
850 /// }
852 /// fn do_the_thing(
853 ///     client: Arc<dyn MyService + Send + Sync + 'static>,
854 /// ) -> impl Future<Item = Out> {...}
855 /// # };
856 /// ```
857 pub mod mock {
858     pub struct MyService<'mock> {
859         pub query: r#impl::my_service::query<'mock>,
860         _marker: ::std::marker::PhantomData<&'mock ()>,
861     }
863     impl dyn super::client::MyService {
864         pub fn mock<'mock>() -> MyService<'mock> {
865             MyService {
866                 query: r#impl::my_service::query::unimplemented(),
867                 _marker: ::std::marker::PhantomData,
868             }
869         }
870     }
872     impl<'mock> super::client::MyService for MyService<'mock> {
873         fn query(
874             &self,
875             arg_u: &crate::types::MyUnion,
876         ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<crate::types::MyStruct, crate::errors::my_service::QueryError>> {
877             let mut closure = self.query.closure.lock().unwrap();
878             let closure: &mut dyn ::std::ops::FnMut(crate::types::MyUnion) -> _ = &mut **closure;
879             ::std::boxed::Box::pin(::futures::future::ready(closure(arg_u.clone())))
880         }
881     }
883     mod r#impl {
884         pub mod my_service {
886             pub struct query<'mock> {
887                 pub(crate) closure: ::std::sync::Mutex<::std::boxed::Box<
888                     dyn ::std::ops::FnMut(crate::types::MyUnion) -> ::std::result::Result<
889                         crate::types::MyStruct,
890                         crate::errors::my_service::QueryError,
891                     > + ::std::marker::Send + ::std::marker::Sync + 'mock,
892                 >>,
893             }
895             #[allow(clippy::redundant_closure)]
896             impl<'mock> query<'mock> {
897                 pub fn unimplemented() -> Self {
898                     Self {
899                         closure: ::std::sync::Mutex::new(::std::boxed::Box::new(|_: crate::types::MyUnion| panic!(
900                             "{}::{} is not mocked",
901                             "MyService",
902                             "query",
903                         ))),
904                     }
905                 }
907                 pub fn ret(&self, value: crate::types::MyStruct) {
908                     self.mock(move |_: crate::types::MyUnion| value.clone());
909                 }
911                 pub fn mock(&self, mut mock: impl ::std::ops::FnMut(crate::types::MyUnion) -> crate::types::MyStruct + ::std::marker::Send + ::std::marker::Sync + 'mock) {
912                     let mut closure = self.closure.lock().unwrap();
913                     *closure = ::std::boxed::Box::new(move |u| ::std::result::Result::Ok(mock(u)));
914                 }
916                 pub fn mock_result(&self, mut mock: impl ::std::ops::FnMut(crate::types::MyUnion) -> ::std::result::Result<crate::types::MyStruct, crate::errors::my_service::QueryError> + ::std::marker::Send + ::std::marker::Sync + 'mock) {
917                     let mut closure = self.closure.lock().unwrap();
918                     *closure = ::std::boxed::Box::new(move |u| mock(u));
919                 }
921                 pub fn throw<E>(&self, exception: E)
922                 where
923                     E: ::std::convert::Into<crate::errors::my_service::QueryError>,
924                     E: ::std::clone::Clone + ::std::marker::Send + ::std::marker::Sync + 'mock,
925                 {
926                     let mut closure = self.closure.lock().unwrap();
927                     *closure = ::std::boxed::Box::new(move |_: crate::types::MyUnion| ::std::result::Result::Err(exception.clone().into()));
928                 }
929             }
930         }
931     }
934 /// Error return types.
935 pub mod errors {
936     /// Errors for MyService functions.
937     pub mod my_service {
939         pub type QueryError = ::fbthrift::NonthrowingFunctionError;
941         impl ::std::convert::From<crate::services::my_service::QueryExn> for
942             ::std::result::Result<crate::types::MyStruct, QueryError>
943         {
944             fn from(e: crate::services::my_service::QueryExn) -> Self {
945                 match e {
946                     crate::services::my_service::QueryExn::Success(res) => {
947                         ::std::result::Result::Ok(res)
948                     }
949                     crate::services::my_service::QueryExn::ApplicationException(aexn) =>
950                         ::std::result::Result::Err(QueryError::ApplicationException(aexn)),
951                 }
952             }
953         }
955     }