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