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 {
14 pub use thrift as thrift;
19 #[derive(Clone, Debug)]
22 Success(crate::types::MyStruct),
23 ApplicationException(::fbthrift::ApplicationException),
26 impl ::std::convert::From<::fbthrift::ApplicationException> for QueryExn {
27 fn from(exn: ::fbthrift::ApplicationException) -> Self {
28 QueryExn::ApplicationException(exn)
32 impl ::fbthrift::ExceptionInfo for QueryExn {
33 fn exn_name(&self) -> &'static str {
35 QueryExn::Success(_) => panic!("ExceptionInfo::exn_name called on Success"),
36 QueryExn::ApplicationException(aexn) => aexn.exn_name(),
40 fn exn_value(&self) -> String {
42 QueryExn::Success(_) => panic!("ExceptionInfo::exn_value called on Success"),
43 QueryExn::ApplicationException(aexn) => aexn.exn_value(),
47 fn exn_is_declared(&self) -> bool {
49 QueryExn::Success(_) => panic!("ExceptionInfo::exn_is_declared called on Success"),
50 QueryExn::ApplicationException(aexn) => aexn.exn_is_declared(),
55 impl ::fbthrift::ResultInfo for QueryExn {
56 fn result_type(&self) -> ::fbthrift::ResultType {
58 QueryExn::Success(_) => ::fbthrift::ResultType::Return,
59 QueryExn::ApplicationException(_aexn) => ::fbthrift::ResultType::Exception,
64 impl ::fbthrift::GetTType for QueryExn {
65 const TTYPE: ::fbthrift::TType = ::fbthrift::TType::Struct;
68 impl<P> ::fbthrift::Serialize<P> for QueryExn
70 P: ::fbthrift::ProtocolWriter,
72 fn write(&self, p: &mut P) {
73 if let QueryExn::ApplicationException(aexn) = self {
76 p.write_struct_begin("Query");
78 QueryExn::Success(inner) => {
81 ::fbthrift::TType::Struct,
87 QueryExn::ApplicationException(_aexn) => unreachable!(),
94 impl<P> ::fbthrift::Deserialize<P> for QueryExn
96 P: ::fbthrift::ProtocolReader,
98 fn read(p: &mut P) -> ::anyhow::Result<Self> {
99 static RETURNS: &[::fbthrift::Field] = &[
100 ::fbthrift::Field::new("Success", ::fbthrift::TType::Struct, 0),
102 let _ = p.read_struct_begin(|_| ())?;
103 let mut once = false;
104 let mut alt = ::std::option::Option::None;
106 let (_, fty, fid) = p.read_field_begin(|_| (), RETURNS)?;
107 match ((fty, fid as ::std::primitive::i32), once) {
108 ((::fbthrift::TType::Stop, _), _) => {
112 ((::fbthrift::TType::Struct, 0i32), false) => {
114 alt = ::std::option::Option::Some(QueryExn::Success(::fbthrift::Deserialize::read(p)?));
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,
121 "unwanted extra union {} field ty {:?} id {}",
131 p.read_struct_end()?;
133 ::fbthrift::ApplicationException::new(
134 ::fbthrift::ApplicationExceptionErrorCode::MissingResult,
135 format!("Empty union {}", "QueryExn"),
144 /// Client implementation for each service in `module`.
147 pub struct MyServiceImpl<P, T, S = ::fbthrift::NoopSpawner> {
149 _phantom: ::std::marker::PhantomData<fn() -> (P, S)>,
152 impl<P, T, S> MyServiceImpl<P, T, S>
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,
166 _phantom: ::std::marker::PhantomData,
170 pub fn transport(&self) -> &T {
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 _;
185 SERVICE_NAME = "MyService";
186 METHOD_NAME = "MyService.query";
188 let args = self::Args_MyService_query {
190 _phantom: ::std::marker::PhantomData,
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(),
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"));
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?;
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))
216 .instrument(::tracing::info_span!("MyService.query"))
221 pub trait MyService: ::std::marker::Send {
224 arg_u: &crate::types::MyUnion,
225 ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<crate::types::MyStruct, crate::errors::my_service::QueryError>>;
228 pub trait MyServiceExt<T>: MyService
230 T: ::fbthrift::Transport,
232 fn query_with_rpc_opts(
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>>;
239 struct Args_MyService_query<'a> {
240 u: &'a crate::types::MyUnion,
241 _phantom: ::std::marker::PhantomData<&'a ()>,
244 impl<'a, P: ::fbthrift::ProtocolWriter> ::fbthrift::Serialize<P> for self::Args_MyService_query<'a> {
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);
252 p.write_field_stop();
253 p.write_struct_end();
257 impl<P, T, S> MyService for MyServiceImpl<P, T, S>
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,
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();
278 impl<P, T, S> MyServiceExt<T> for MyServiceImpl<P, T, S>
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,
287 fn query_with_rpc_opts(
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>> {
299 impl<'a, S> MyService for S
301 S: ::std::convert::AsRef<dyn MyService + 'a>,
302 S: ::std::marker::Send,
306 arg_u: &crate::types::MyUnion,
307 ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<crate::types::MyStruct, crate::errors::my_service::QueryError>> {
314 impl<'a, S, T> MyServiceExt<T> for S
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,
321 fn query_with_rpc_opts(
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(
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
341 /// # const _: &str = stringify! {
342 /// use bgs::client::BuckGraphService;
344 /// let protocol = BinaryProtocol::new();
345 /// let transport = HttpClient::new();
346 /// let client = <dyn BuckGraphService>::new(protocol, transport);
353 ) -> ::std::sync::Arc<impl MyService + ::std::marker::Send + 'static>
355 P: ::fbthrift::Protocol<Frame = T>,
356 T: ::fbthrift::Transport,
357 P::Deserializer: ::std::marker::Send,
359 let spawner = ::fbthrift::help::NoopSpawner;
360 Self::with_spawner(protocol, transport, spawner)
363 pub fn with_spawner<P, T, S>(
367 ) -> ::std::sync::Arc<impl MyService + ::std::marker::Send + 'static>
369 P: ::fbthrift::Protocol<Frame = T>,
370 T: ::fbthrift::Transport,
371 P::Deserializer: ::std::marker::Send,
372 S: ::fbthrift::help::Spawner,
376 ::std::sync::Arc::new(MyServiceImpl::<P, T, S>::new(transport))
380 impl<T> dyn MyServiceExt<T>
382 T: ::fbthrift::Transport,
387 ) -> ::std::sync::Arc<impl MyServiceExt<T> + ::std::marker::Send + 'static>
389 P: ::fbthrift::Protocol<Frame = T>,
390 P::Deserializer: ::std::marker::Send,
392 let spawner = ::fbthrift::help::NoopSpawner;
393 Self::with_spawner(protocol, transport, spawner)
396 pub fn with_spawner<P, S>(
400 ) -> ::std::sync::Arc<impl MyServiceExt<T> + ::std::marker::Send + 'static>
402 P: ::fbthrift::Protocol<Frame = T>,
403 P::Deserializer: ::std::marker::Send,
404 S: ::fbthrift::help::Spawner,
408 ::std::sync::Arc::new(MyServiceImpl::<P, T, S>::new(transport))
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>
422 P: ::fbthrift::Protocol<Frame = T>,
423 T: ::fbthrift::Transport + ::std::marker::Sync,
424 P::Deserializer: ::std::marker::Send,
425 S: ::fbthrift::help::Spawner,
427 <dyn MyService>::with_spawner(protocol, transport, spawner)
433 /// Server definitions for `module`.
435 #[::async_trait::async_trait]
436 pub trait MyService: ::std::marker::Send + ::std::marker::Sync + 'static {
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(
452 #[::async_trait::async_trait]
453 impl<T> MyService for ::std::boxed::Box<T>
455 T: MyService + Send + Sync + ?Sized,
459 u: crate::types::MyUnion,
460 ) -> ::std::result::Result<
461 crate::types::MyStruct,
462 crate::services::my_service::QueryExn> {
469 /// Processor for MyService's methods.
470 #[derive(Clone, Debug)]
471 pub struct MyServiceProcessor<P, H, R, RS> {
473 supa: ::fbthrift::NullServiceProcessor<P, R, RS>,
474 _phantom: ::std::marker::PhantomData<(P, H, R, RS)>,
477 struct Args_MyService_query {
478 u: crate::types::MyUnion,
480 impl<P: ::fbthrift::ProtocolReader> ::fbthrift::Deserialize<P> for self::Args_MyService_query {
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),
487 let mut field_u = ::std::option::Option::None;
488 let _ = p.read_struct_begin(|_| ())?;
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)?,
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"))?,
506 impl<P, H, R, RS> MyServiceProcessor<P, H, R, RS>
508 P: ::fbthrift::Protocol + ::std::marker::Send + ::std::marker::Sync + 'static,
509 P::Deserializer: ::std::marker::Send,
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,
516 pub fn new(service: H) -> Self {
519 supa: ::fbthrift::NullServiceProcessor::new(),
520 _phantom: ::std::marker::PhantomData,
524 pub fn into_inner(self) -> H {
528 #[::tracing::instrument(skip_all, fields(method = "MyService.query"))]
529 async fn handle_query<'a>(
531 p: &'a mut P::Deserializer,
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 _;
541 SERVICE_NAME = "MyService";
542 METHOD_NAME = "MyService.query";
544 let mut ctx_stack = req_ctxt.get_context_stack(
545 SERVICE_NAME.as_cstr(),
546 METHOD_NAME.as_cstr(),
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(),
555 ::fbthrift::ContextStack::post_read(&mut ctx_stack, 0)?;
557 let res = ::std::panic::AssertUnwindSafe(
563 .instrument(::tracing::info_span!("service_handler", method = "MyService.query"))
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)
572 ::std::result::Result::Ok(::std::result::Result::Err(crate::services::my_service::QueryExn::Success(_))) => {
574 "{} attempted to return success via error",
578 ::std::result::Result::Ok(::std::result::Result::Err(exn)) => {
579 ::tracing::error!(method = "MyService.query", exception = ?exn);
582 ::std::result::Result::Err(exn) => {
583 let aexn = ::fbthrift::ApplicationException::handler_panic("MyService.query", exn);
584 crate::services::my_service::QueryExn::ApplicationException(aexn)
588 let env = ::fbthrift::help::serialize_result_envelope::<P, R, _>(
590 METHOD_NAME.as_cstr(),
596 reply_state.lock().unwrap().send_reply(env);
601 #[::async_trait::async_trait]
602 impl<P, H, R, RS> ::fbthrift::ServiceProcessor<P> for MyServiceProcessor<P, H, R, RS>
604 P: ::fbthrift::Protocol + ::std::marker::Send + ::std::marker::Sync + 'static,
605 P::Deserializer: ::std::marker::Send,
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
613 type RequestContext = R;
614 type ReplyState = RS;
617 fn method_idx(&self, name: &[::std::primitive::u8]) -> ::std::result::Result<::std::primitive::usize, ::fbthrift::ApplicationException> {
619 b"query" => ::std::result::Result::Ok(0usize),
620 _ => ::std::result::Result::Err(::fbthrift::ApplicationException::unknown_method()),
624 #[allow(clippy::match_single_binding)]
625 async fn handle_method(
627 idx: ::std::primitive::usize,
628 _p: &mut P::Deserializer,
630 _reply_state: ::std::sync::Arc<::std::sync::Mutex<RS>>,
631 _seqid: ::std::primitive::u32,
632 ) -> ::anyhow::Result<()> {
635 self.handle_query(_p, _r, _reply_state, _seqid).await
638 "{}: unexpected method idx {}",
639 "MyServiceProcessor",
645 #[allow(clippy::match_single_binding)]
647 fn create_interaction_idx(&self, name: &str) -> ::anyhow::Result<::std::primitive::usize> {
649 _ => ::anyhow::bail!("Unknown interaction"),
653 #[allow(clippy::match_single_binding)]
654 fn handle_create_interaction(
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>
662 "{}: unexpected method idx {}",
663 "MyServiceProcessor",
670 #[::async_trait::async_trait]
671 impl<P, H, R, RS> ::fbthrift::ThriftService<P::Frame> for MyServiceProcessor<P, H, R, RS>
673 P: ::fbthrift::Protocol + ::std::marker::Send + ::std::marker::Sync + 'static,
674 P::Deserializer: ::std::marker::Send,
675 P::Frame: ::std::marker::Send + 'static,
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
683 type RequestContext = R;
684 type ReplyState = RS;
686 #[tracing::instrument(level="trace", skip_all, fields(service = "MyService"))]
689 req: ::fbthrift::ProtocolDecoded<P>,
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)
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;
709 self.handle_method(idx, &mut p, req_ctxt, reply_state, seqid).await?;
710 p.read_message_end()?;
715 fn create_interaction(
718 ) -> ::anyhow::Result<
719 ::std::sync::Arc<dyn ::fbthrift::ThriftService<P::Frame, Handler = (), RequestContext = R, ReplyState = RS> + ::std::marker::Send + 'static>
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);
729 self.handle_create_interaction(idx)
733 /// Construct a new instance of a MyService service.
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,
741 ) -> ::std::result::Result<::std::boxed::Box<dyn ::fbthrift::ThriftService<F, Handler = H, RequestContext = R, ReplyState = RS> + ::std::marker::Send + 'static>, ::fbthrift::ApplicationException>
743 F: ::fbthrift::Framing + ::std::marker::Send + ::std::marker::Sync + 'static,
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
750 ::fbthrift::ProtocolID::BinaryProtocol => {
751 ::std::result::Result::Ok(::std::boxed::Box::new(MyServiceProcessor::<::fbthrift::BinaryProtocol<F>, H, R, RS>::new(handler)))
753 ::fbthrift::ProtocolID::CompactProtocol => {
754 ::std::result::Result::Ok(::std::boxed::Box::new(MyServiceProcessor::<::fbthrift::CompactProtocol<F>, H, R, RS>::new(handler)))
757 ::tracing::error!(method = "MyService.", invalid_protocol = ?bad);
758 ::std::result::Result::Err(::fbthrift::ApplicationException::invalid_protocol(bad))
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:
770 /// service MyService {
771 /// FunctionResponse myFunction(
772 /// 1: FunctionRequest request,
774 /// 1: StorageException s,
775 /// 2: NotFoundException n,
778 /// // other functions
782 /// we would end up with this mock object under crate::mock::MyService:
785 /// # const _: &str = stringify! {
786 /// impl crate::client::MyService for MyService<'mock> {...}
788 /// pub struct MyService<'mock> {
789 /// pub myFunction: myFunction<'mock>,
793 /// impl dyn crate::client::MyService {
794 /// pub fn mock<'mock>() -> MyService<'mock>;
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
804 /// mock: impl FnMut(FunctionRequest) -> FunctionResponse + Send + Sync + 'mock,
807 /// // invoke closure to compute response
808 /// pub fn mock_result(
810 /// mock: impl FnMut(FunctionRequest) -> Result<FunctionResponse, crate::services::MyService::MyFunctionExn> + Send + Sync + 'mock,
813 /// // return one of the function's declared exceptions
814 /// pub fn throw<E>(&self, exception: E)
816 /// E: Clone + Into<crate::services::MyService::MyFunctionExn> + Send + Sync + 'mock;
819 /// impl From<StorageException> for MyFunctionExn {...}
820 /// impl From<NotFoundException> for MyFunctionExn {...}
824 /// The intended usage from a test would be:
827 /// # const _: &str = stringify! {
828 /// use std::sync::Arc;
829 /// use thrift_if::client::MyService;
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());
853 /// client: Arc<dyn MyService + Send + Sync + 'static>,
854 /// ) -> impl Future<Item = Out> {...}
858 pub struct MyService<'mock> {
859 pub query: r#impl::my_service::query<'mock>,
860 _marker: ::std::marker::PhantomData<&'mock ()>,
863 impl dyn super::client::MyService {
864 pub fn mock<'mock>() -> MyService<'mock> {
866 query: r#impl::my_service::query::unimplemented(),
867 _marker: ::std::marker::PhantomData,
872 impl<'mock> super::client::MyService for MyService<'mock> {
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())))
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,
895 #[allow(clippy::redundant_closure)]
896 impl<'mock> query<'mock> {
897 pub fn unimplemented() -> Self {
899 closure: ::std::sync::Mutex::new(::std::boxed::Box::new(|_: crate::types::MyUnion| panic!(
900 "{}::{} is not mocked",
907 pub fn ret(&self, value: crate::types::MyStruct) {
908 self.mock(move |_: crate::types::MyUnion| value.clone());
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)));
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));
921 pub fn throw<E>(&self, exception: E)
923 E: ::std::convert::Into<crate::errors::my_service::QueryError>,
924 E: ::std::clone::Clone + ::std::marker::Send + ::std::marker::Sync + 'mock,
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()));
934 /// Error return types.
936 /// Errors for MyService functions.
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>
944 fn from(e: crate::services::my_service::QueryExn) -> Self {
946 crate::services::my_service::QueryExn::Success(res) => {
947 ::std::result::Result::Ok(res)
949 crate::services::my_service::QueryExn::ApplicationException(aexn) =>
950 ::std::result::Result::Err(QueryError::ApplicationException(aexn)),