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::*;
13 pub mod dependencies {
17 pub mod test_service {
18 #[derive(Clone, Debug)]
21 Success(::std::primitive::i64),
22 ApplicationException(::fbthrift::ApplicationException),
25 impl ::std::convert::From<::fbthrift::ApplicationException> for InitExn {
26 fn from(exn: ::fbthrift::ApplicationException) -> Self {
27 InitExn::ApplicationException(exn)
31 impl ::fbthrift::ExceptionInfo for InitExn {
32 fn exn_name(&self) -> &'static str {
34 InitExn::Success(_) => panic!("ExceptionInfo::exn_name called on Success"),
35 InitExn::ApplicationException(aexn) => aexn.exn_name(),
39 fn exn_value(&self) -> String {
41 InitExn::Success(_) => panic!("ExceptionInfo::exn_value called on Success"),
42 InitExn::ApplicationException(aexn) => aexn.exn_value(),
46 fn exn_is_declared(&self) -> bool {
48 InitExn::Success(_) => panic!("ExceptionInfo::exn_is_declared called on Success"),
49 InitExn::ApplicationException(aexn) => aexn.exn_is_declared(),
54 impl ::fbthrift::ResultInfo for InitExn {
55 fn result_type(&self) -> ::fbthrift::ResultType {
57 InitExn::Success(_) => ::fbthrift::ResultType::Return,
58 InitExn::ApplicationException(_aexn) => ::fbthrift::ResultType::Exception,
63 impl ::fbthrift::GetTType for InitExn {
64 const TTYPE: ::fbthrift::TType = ::fbthrift::TType::Struct;
67 impl<P> ::fbthrift::Serialize<P> for InitExn
69 P: ::fbthrift::ProtocolWriter,
71 fn write(&self, p: &mut P) {
72 if let InitExn::ApplicationException(aexn) = self {
75 p.write_struct_begin("Init");
77 InitExn::Success(inner) => {
80 ::fbthrift::TType::I64,
86 InitExn::ApplicationException(_aexn) => unreachable!(),
93 impl<P> ::fbthrift::Deserialize<P> for InitExn
95 P: ::fbthrift::ProtocolReader,
97 fn read(p: &mut P) -> ::anyhow::Result<Self> {
98 static RETURNS: &[::fbthrift::Field] = &[
99 ::fbthrift::Field::new("Success", ::fbthrift::TType::I64, 0),
101 let _ = p.read_struct_begin(|_| ())?;
102 let mut once = false;
103 let mut alt = ::std::option::Option::None;
105 let (_, fty, fid) = p.read_field_begin(|_| (), RETURNS)?;
106 match ((fty, fid as ::std::primitive::i32), once) {
107 ((::fbthrift::TType::Stop, _), _) => {
111 ((::fbthrift::TType::I64, 0i32), false) => {
113 alt = ::std::option::Option::Some(InitExn::Success(::fbthrift::Deserialize::read(p)?));
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,
120 "unwanted extra union {} field ty {:?} id {}",
130 p.read_struct_end()?;
132 ::fbthrift::ApplicationException::new(
133 ::fbthrift::ApplicationExceptionErrorCode::MissingResult,
134 format!("Empty union {}", "InitExn"),
143 /// Client implementation for each service in `module`.
146 pub struct TestServiceImpl<P, T, S = ::fbthrift::NoopSpawner> {
148 _phantom: ::std::marker::PhantomData<fn() -> (P, S)>,
151 impl<P, T, S> TestServiceImpl<P, T, S>
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,
165 _phantom: ::std::marker::PhantomData,
169 pub fn transport(&self) -> &T {
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 _;
184 SERVICE_NAME = "TestService";
185 METHOD_NAME = "TestService.init";
187 let args = self::Args_TestService_init {
189 _phantom: ::std::marker::PhantomData,
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(),
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"));
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?;
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))
215 .instrument(::tracing::info_span!("TestService.init"))
220 pub trait TestService: ::std::marker::Send {
223 arg_int1: ::std::primitive::i64,
224 ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<::std::primitive::i64, crate::errors::test_service::InitError>>;
227 pub trait TestServiceExt<T>: TestService
229 T: ::fbthrift::Transport,
231 fn init_with_rpc_opts(
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>>;
238 struct Args_TestService_init<'a> {
239 int1: ::std::primitive::i64,
240 _phantom: ::std::marker::PhantomData<&'a ()>,
243 impl<'a, P: ::fbthrift::ProtocolWriter> ::fbthrift::Serialize<P> for self::Args_TestService_init<'a> {
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);
251 p.write_field_stop();
252 p.write_struct_end();
256 impl<P, T, S> TestService for TestServiceImpl<P, T, S>
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,
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();
277 impl<P, T, S> TestServiceExt<T> for TestServiceImpl<P, T, S>
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,
286 fn init_with_rpc_opts(
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>> {
298 impl<'a, S> TestService for S
300 S: ::std::convert::AsRef<dyn TestService + 'a>,
301 S: ::std::marker::Send,
305 arg_int1: ::std::primitive::i64,
306 ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<::std::primitive::i64, crate::errors::test_service::InitError>> {
313 impl<'a, S, T> TestServiceExt<T> for S
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,
320 fn init_with_rpc_opts(
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(
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
340 /// # const _: &str = stringify! {
341 /// use bgs::client::BuckGraphService;
343 /// let protocol = BinaryProtocol::new();
344 /// let transport = HttpClient::new();
345 /// let client = <dyn BuckGraphService>::new(protocol, transport);
348 impl dyn TestService {
352 ) -> ::std::sync::Arc<impl TestService + ::std::marker::Send + 'static>
354 P: ::fbthrift::Protocol<Frame = T>,
355 T: ::fbthrift::Transport,
356 P::Deserializer: ::std::marker::Send,
358 let spawner = ::fbthrift::help::NoopSpawner;
359 Self::with_spawner(protocol, transport, spawner)
362 pub fn with_spawner<P, T, S>(
366 ) -> ::std::sync::Arc<impl TestService + ::std::marker::Send + 'static>
368 P: ::fbthrift::Protocol<Frame = T>,
369 T: ::fbthrift::Transport,
370 P::Deserializer: ::std::marker::Send,
371 S: ::fbthrift::help::Spawner,
375 ::std::sync::Arc::new(TestServiceImpl::<P, T, S>::new(transport))
379 impl<T> dyn TestServiceExt<T>
381 T: ::fbthrift::Transport,
386 ) -> ::std::sync::Arc<impl TestServiceExt<T> + ::std::marker::Send + 'static>
388 P: ::fbthrift::Protocol<Frame = T>,
389 P::Deserializer: ::std::marker::Send,
391 let spawner = ::fbthrift::help::NoopSpawner;
392 Self::with_spawner(protocol, transport, spawner)
395 pub fn with_spawner<P, S>(
399 ) -> ::std::sync::Arc<impl TestServiceExt<T> + ::std::marker::Send + 'static>
401 P: ::fbthrift::Protocol<Frame = T>,
402 P::Deserializer: ::std::marker::Send,
403 S: ::fbthrift::help::Spawner,
407 ::std::sync::Arc::new(TestServiceImpl::<P, T, S>::new(transport))
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>
421 P: ::fbthrift::Protocol<Frame = T>,
422 T: ::fbthrift::Transport + ::std::marker::Sync,
423 P::Deserializer: ::std::marker::Send,
424 S: ::fbthrift::help::Spawner,
426 <dyn TestService>::with_spawner(protocol, transport, spawner)
432 /// Server definitions for `module`.
434 #[::async_trait::async_trait]
435 pub trait TestService: ::std::marker::Send + ::std::marker::Sync + 'static {
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(
451 #[::async_trait::async_trait]
452 impl<T> TestService for ::std::boxed::Box<T>
454 T: TestService + Send + Sync + ?Sized,
458 int1: ::std::primitive::i64,
459 ) -> ::std::result::Result<
460 ::std::primitive::i64,
461 crate::services::test_service::InitExn> {
468 /// Processor for TestService's methods.
469 #[derive(Clone, Debug)]
470 pub struct TestServiceProcessor<P, H, R, RS> {
472 supa: ::fbthrift::NullServiceProcessor<P, R, RS>,
473 _phantom: ::std::marker::PhantomData<(P, H, R, RS)>,
476 struct Args_TestService_init {
477 int1: ::std::primitive::i64,
479 impl<P: ::fbthrift::ProtocolReader> ::fbthrift::Deserialize<P> for self::Args_TestService_init {
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),
486 let mut field_int1 = ::std::option::Option::None;
487 let _ = p.read_struct_begin(|_| ())?;
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)?,
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"))?,
505 impl<P, H, R, RS> TestServiceProcessor<P, H, R, RS>
507 P: ::fbthrift::Protocol + ::std::marker::Send + ::std::marker::Sync + 'static,
508 P::Deserializer: ::std::marker::Send,
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,
515 pub fn new(service: H) -> Self {
518 supa: ::fbthrift::NullServiceProcessor::new(),
519 _phantom: ::std::marker::PhantomData,
523 pub fn into_inner(self) -> H {
527 #[::tracing::instrument(skip_all, fields(method = "TestService.init"))]
528 async fn handle_init<'a>(
530 p: &'a mut P::Deserializer,
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 _;
540 SERVICE_NAME = "TestService";
541 METHOD_NAME = "TestService.init";
543 let mut ctx_stack = req_ctxt.get_context_stack(
544 SERVICE_NAME.as_cstr(),
545 METHOD_NAME.as_cstr(),
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(),
554 ::fbthrift::ContextStack::post_read(&mut ctx_stack, 0)?;
556 let res = ::std::panic::AssertUnwindSafe(
562 .instrument(::tracing::info_span!("service_handler", method = "TestService.init"))
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)
571 ::std::result::Result::Ok(::std::result::Result::Err(crate::services::test_service::InitExn::Success(_))) => {
573 "{} attempted to return success via error",
577 ::std::result::Result::Ok(::std::result::Result::Err(exn)) => {
578 ::tracing::error!(method = "TestService.init", exception = ?exn);
581 ::std::result::Result::Err(exn) => {
582 let aexn = ::fbthrift::ApplicationException::handler_panic("TestService.init", exn);
583 crate::services::test_service::InitExn::ApplicationException(aexn)
587 let env = ::fbthrift::help::serialize_result_envelope::<P, R, _>(
589 METHOD_NAME.as_cstr(),
595 reply_state.lock().unwrap().send_reply(env);
600 #[::async_trait::async_trait]
601 impl<P, H, R, RS> ::fbthrift::ServiceProcessor<P> for TestServiceProcessor<P, H, R, RS>
603 P: ::fbthrift::Protocol + ::std::marker::Send + ::std::marker::Sync + 'static,
604 P::Deserializer: ::std::marker::Send,
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
612 type RequestContext = R;
613 type ReplyState = RS;
616 fn method_idx(&self, name: &[::std::primitive::u8]) -> ::std::result::Result<::std::primitive::usize, ::fbthrift::ApplicationException> {
618 b"init" => ::std::result::Result::Ok(0usize),
619 _ => ::std::result::Result::Err(::fbthrift::ApplicationException::unknown_method()),
623 #[allow(clippy::match_single_binding)]
624 async fn handle_method(
626 idx: ::std::primitive::usize,
627 _p: &mut P::Deserializer,
629 _reply_state: ::std::sync::Arc<::std::sync::Mutex<RS>>,
630 _seqid: ::std::primitive::u32,
631 ) -> ::anyhow::Result<()> {
634 self.handle_init(_p, _r, _reply_state, _seqid).await
637 "{}: unexpected method idx {}",
638 "TestServiceProcessor",
644 #[allow(clippy::match_single_binding)]
646 fn create_interaction_idx(&self, name: &str) -> ::anyhow::Result<::std::primitive::usize> {
648 _ => ::anyhow::bail!("Unknown interaction"),
652 #[allow(clippy::match_single_binding)]
653 fn handle_create_interaction(
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>
661 "{}: unexpected method idx {}",
662 "TestServiceProcessor",
669 #[::async_trait::async_trait]
670 impl<P, H, R, RS> ::fbthrift::ThriftService<P::Frame> for TestServiceProcessor<P, H, R, RS>
672 P: ::fbthrift::Protocol + ::std::marker::Send + ::std::marker::Sync + 'static,
673 P::Deserializer: ::std::marker::Send,
674 P::Frame: ::std::marker::Send + 'static,
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
682 type RequestContext = R;
683 type ReplyState = RS;
685 #[tracing::instrument(level="trace", skip_all, fields(service = "TestService"))]
688 req: ::fbthrift::ProtocolDecoded<P>,
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)
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;
708 self.handle_method(idx, &mut p, req_ctxt, reply_state, seqid).await?;
709 p.read_message_end()?;
714 fn create_interaction(
717 ) -> ::anyhow::Result<
718 ::std::sync::Arc<dyn ::fbthrift::ThriftService<P::Frame, Handler = (), RequestContext = R, ReplyState = RS> + ::std::marker::Send + 'static>
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);
728 self.handle_create_interaction(idx)
732 /// Construct a new instance of a TestService service.
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,
740 ) -> ::std::result::Result<::std::boxed::Box<dyn ::fbthrift::ThriftService<F, Handler = H, RequestContext = R, ReplyState = RS> + ::std::marker::Send + 'static>, ::fbthrift::ApplicationException>
742 F: ::fbthrift::Framing + ::std::marker::Send + ::std::marker::Sync + 'static,
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
749 ::fbthrift::ProtocolID::BinaryProtocol => {
750 ::std::result::Result::Ok(::std::boxed::Box::new(TestServiceProcessor::<::fbthrift::BinaryProtocol<F>, H, R, RS>::new(handler)))
752 ::fbthrift::ProtocolID::CompactProtocol => {
753 ::std::result::Result::Ok(::std::boxed::Box::new(TestServiceProcessor::<::fbthrift::CompactProtocol<F>, H, R, RS>::new(handler)))
756 ::tracing::error!(method = "TestService.", invalid_protocol = ?bad);
757 ::std::result::Result::Err(::fbthrift::ApplicationException::invalid_protocol(bad))
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:
769 /// service MyService {
770 /// FunctionResponse myFunction(
771 /// 1: FunctionRequest request,
773 /// 1: StorageException s,
774 /// 2: NotFoundException n,
777 /// // other functions
781 /// we would end up with this mock object under crate::mock::MyService:
784 /// # const _: &str = stringify! {
785 /// impl crate::client::MyService for MyService<'mock> {...}
787 /// pub struct MyService<'mock> {
788 /// pub myFunction: myFunction<'mock>,
792 /// impl dyn crate::client::MyService {
793 /// pub fn mock<'mock>() -> MyService<'mock>;
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
803 /// mock: impl FnMut(FunctionRequest) -> FunctionResponse + Send + Sync + 'mock,
806 /// // invoke closure to compute response
807 /// pub fn mock_result(
809 /// mock: impl FnMut(FunctionRequest) -> Result<FunctionResponse, crate::services::MyService::MyFunctionExn> + Send + Sync + 'mock,
812 /// // return one of the function's declared exceptions
813 /// pub fn throw<E>(&self, exception: E)
815 /// E: Clone + Into<crate::services::MyService::MyFunctionExn> + Send + Sync + 'mock;
818 /// impl From<StorageException> for MyFunctionExn {...}
819 /// impl From<NotFoundException> for MyFunctionExn {...}
823 /// The intended usage from a test would be:
826 /// # const _: &str = stringify! {
827 /// use std::sync::Arc;
828 /// use thrift_if::client::MyService;
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());
852 /// client: Arc<dyn MyService + Send + Sync + 'static>,
853 /// ) -> impl Future<Item = Out> {...}
857 pub struct TestService<'mock> {
858 pub init: r#impl::test_service::init<'mock>,
859 _marker: ::std::marker::PhantomData<&'mock ()>,
862 impl dyn super::client::TestService {
863 pub fn mock<'mock>() -> TestService<'mock> {
865 init: r#impl::test_service::init::unimplemented(),
866 _marker: ::std::marker::PhantomData,
871 impl<'mock> super::client::TestService for TestService<'mock> {
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())))
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,
894 #[allow(clippy::redundant_closure)]
895 impl<'mock> init<'mock> {
896 pub fn unimplemented() -> Self {
898 closure: ::std::sync::Mutex::new(::std::boxed::Box::new(|_: ::std::primitive::i64| panic!(
899 "{}::{} is not mocked",
906 pub fn ret(&self, value: ::std::primitive::i64) {
907 self.mock(move |_: ::std::primitive::i64| value.clone());
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)));
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));
920 pub fn throw<E>(&self, exception: E)
922 E: ::std::convert::Into<crate::errors::test_service::InitError>,
923 E: ::std::clone::Clone + ::std::marker::Send + ::std::marker::Sync + 'mock,
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()));
933 /// Error return types.
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>
943 fn from(e: crate::services::test_service::InitExn) -> Self {
945 crate::services::test_service::InitExn::Success(res) => {
946 ::std::result::Result::Ok(res)
948 crate::services::test_service::InitExn::ApplicationException(aexn) =>
949 ::std::result::Result::Err(InitError::ApplicationException(aexn)),