// @generated by Thrift for thrift/compiler/test/fixtures/doctext/src/module.thrift
// This file is probably not the place you want to edit!

#![recursion_limit = "100000000"]
#![allow(non_camel_case_types, non_snake_case, non_upper_case_globals, unused_crate_dependencies, clippy::all)]

pub use self::consts::*;
pub use self::errors::*;
pub use self::types::*;

/// Constant definitions for `module`.
pub mod consts {
    #[doc = "Constant foo"]
    pub const FOO: &::std::primitive::str = "foo";

    #[doc = "Multi-\nline\nslash comment"]
    pub const BAR: ::std::primitive::i32 = 123;

    #[doc = "BIFF has your mail"]
    pub const BIFF: ::std::primitive::i32 = 0;

    pub const SHOUTY: ::std::primitive::i32 = 11;

}

pub mod types;

#[doc(hidden)]
pub mod dependencies {
}

pub mod services {
    pub mod c {
        #![doc = "Detailed overview of service"]

        #[derive(Clone, Debug)]
        pub enum FExn {
            #[doc(hidden)]
            Success(()),
            ApplicationException(::fbthrift::ApplicationException),
        }

        impl ::std::convert::From<crate::errors::c::FError> for FExn {
            fn from(err: crate::errors::c::FError) -> Self {
                match err {
                    crate::errors::c::FError::ApplicationException(aexn) => FExn::ApplicationException(aexn),
                    crate::errors::c::FError::ThriftError(err) => FExn::ApplicationException(::fbthrift::ApplicationException {
                        message: err.to_string(),
                        type_: ::fbthrift::ApplicationExceptionErrorCode::InternalError,
                    }),
                }
            }
        }

        impl ::std::convert::From<::fbthrift::ApplicationException> for FExn {
            fn from(exn: ::fbthrift::ApplicationException) -> Self {
                Self::ApplicationException(exn)
            }
        }

        impl ::fbthrift::ExceptionInfo for FExn {
            fn exn_name(&self) -> &'static str {
                match self {
                    Self::Success(_) => panic!("ExceptionInfo::exn_name called on Success"),
                    Self::ApplicationException(aexn) => aexn.exn_name(),
                }
            }

            fn exn_value(&self) -> String {
                match self {
                    Self::Success(_) => panic!("ExceptionInfo::exn_value called on Success"),
                    Self::ApplicationException(aexn) => aexn.exn_value(),
                }
            }

            fn exn_is_declared(&self) -> bool {
                match self {
                    Self::Success(_) => panic!("ExceptionInfo::exn_is_declared called on Success"),
                    Self::ApplicationException(aexn) => aexn.exn_is_declared(),
                }
            }
        }

        impl ::fbthrift::ResultInfo for FExn {
            fn result_type(&self) -> ::fbthrift::ResultType {
                match self {
                    Self::Success(_) => ::fbthrift::ResultType::Return,
                    Self::ApplicationException(_aexn) => ::fbthrift::ResultType::Exception,
                }
            }
        }

        impl ::fbthrift::GetTType for FExn {
            const TTYPE: ::fbthrift::TType = ::fbthrift::TType::Struct;
        }

        impl<P> ::fbthrift::Serialize<P> for FExn
        where
            P: ::fbthrift::ProtocolWriter,
        {
            fn write(&self, p: &mut P) {
                if let Self::ApplicationException(aexn) = self {
                    return aexn.write(p);
                }
                p.write_struct_begin("F");
                match self {
                    Self::Success(inner) => {
                        p.write_field_begin(
                            "Success",
                            ::fbthrift::TType::Void,
                            0i16,
                        );
                        inner.write(p);
                        p.write_field_end();
                    }
                    Self::ApplicationException(_aexn) => unreachable!(),
                }
                p.write_field_stop();
                p.write_struct_end();
            }
        }

        impl<P> ::fbthrift::Deserialize<P> for FExn
        where
            P: ::fbthrift::ProtocolReader,
        {
            fn read(p: &mut P) -> ::anyhow::Result<Self> {
                static RETURNS: &[::fbthrift::Field] = &[
                    ::fbthrift::Field::new("Success", ::fbthrift::TType::Void, 0),
                ];
                let _ = p.read_struct_begin(|_| ())?;
                let mut once = false;
                let mut alt = Self::Success(());
                loop {
                    let (_, fty, fid) = p.read_field_begin(|_| (), RETURNS)?;
                    match ((fty, fid as ::std::primitive::i32), once) {
                        ((::fbthrift::TType::Stop, _), _) => {
                            p.read_field_end()?;
                            break;
                        }
                        ((::fbthrift::TType::Void, 0i32), false) => {
                            once = true;
                            alt = Self::Success(::fbthrift::Deserialize::read(p)?);
                        }
                        ((ty, _id), false) => p.skip(ty)?,
                        ((badty, badid), true) => return ::std::result::Result::Err(::std::convert::From::from(
                            ::fbthrift::ApplicationException::new(
                                ::fbthrift::ApplicationExceptionErrorCode::ProtocolError,
                                format!(
                                    "unwanted extra union {} field ty {:?} id {}",
                                    "FExn",
                                    badty,
                                    badid,
                                ),
                            )
                        )),
                    }
                    p.read_field_end()?;
                }
                p.read_struct_end()?;
                ::std::result::Result::Ok(alt)
            }
        }

        #[derive(Clone, Debug)]
        pub enum NumbersStreamExn {
            #[doc(hidden)]
            Success(crate::types::number),
            ApplicationException(::fbthrift::ApplicationException),
        }

        impl ::fbthrift::ExceptionInfo for NumbersStreamExn {
            fn exn_name(&self) -> &'static str {
                match self {
                    Self::Success(_) => panic!("ExceptionInfo::exn_name called on Success"),
                    Self::ApplicationException(aexn) => aexn.exn_name(),
                }
            }

            fn exn_value(&self) -> String {
                match self {
                    Self::Success(_) => panic!("ExceptionInfo::exn_value called on Success"),
                    Self::ApplicationException(aexn) => aexn.exn_value(),
                }
            }

            fn exn_is_declared(&self) -> bool {
                match self {
                    Self::Success(_) => panic!("ExceptionInfo::exn_is_declared called on Success"),
                    Self::ApplicationException(aexn) => aexn.exn_is_declared(),
                }
            }
        }

        impl ::fbthrift::ResultInfo for NumbersStreamExn {
            fn result_type(&self) -> ::fbthrift::ResultType {
                match self {
                    Self::Success(_) => ::fbthrift::ResultType::Return,
                    Self::ApplicationException(_aexn) => ::fbthrift::ResultType::Exception,
                }
            }
        }

        impl ::std::convert::From<::fbthrift::ApplicationException> for NumbersStreamExn {
            fn from(exn: ::fbthrift::ApplicationException) -> Self {
                Self::ApplicationException(exn)
            }
        }

        impl ::fbthrift::GetTType for NumbersStreamExn {
            const TTYPE: ::fbthrift::TType = ::fbthrift::TType::Struct;
        }

        impl<P> ::fbthrift::Serialize<P> for NumbersStreamExn
        where
            P: ::fbthrift::ProtocolWriter,
        {
            fn write(&self, p: &mut P) {
                if let Self::ApplicationException(aexn) = self {
                    return aexn.write(p);
                }
                p.write_struct_begin("Numbers");
                match self {
                    Self::Success(inner) => {
                        p.write_field_begin(
                            "Success",
                            ::fbthrift::TType::I32,
                            0i16,
                        );
                        inner.write(p);
                        p.write_field_end();
                    }
                    Self::ApplicationException(_) => unreachable!(),
                }
                p.write_field_stop();
                p.write_struct_end();
            }
        }

        impl<P> ::fbthrift::Deserialize<P> for NumbersStreamExn
        where
            P: ::fbthrift::ProtocolReader,
        {
            fn read(p: &mut P) -> ::anyhow::Result<Self> {
                static RETURNS: &[::fbthrift::Field] = &[
                    ::fbthrift::Field::new("Success", ::fbthrift::TType::Stream, 0),
                ];
                let _ = p.read_struct_begin(|_| ())?;
                let mut once = false;
                let mut alt = ::std::option::Option::None;
                loop {
                    let (_, fty, fid) = p.read_field_begin(|_| (), RETURNS)?;
                    match ((fty, fid as ::std::primitive::i32), once) {
                        ((::fbthrift::TType::Stop, _), _) => {
                            p.read_field_end()?;
                            break;
                        }
                        ((::fbthrift::TType::I32, 0i32), false) => {
                            once = true;
                            alt = ::std::option::Option::Some(Self::Success(::fbthrift::Deserialize::read(p)?));
                        }
                        ((ty, _id), false) => p.skip(ty)?,
                        ((badty, badid), true) => return ::std::result::Result::Err(::std::convert::From::from(
                            ::fbthrift::ApplicationException::new(
                                ::fbthrift::ApplicationExceptionErrorCode::ProtocolError,
                                format!(
                                    "unwanted extra union {} field ty {:?} id {}",
                                    "NumbersStreamExn",
                                    badty,
                                    badid,
                                ),
                            )
                        )),
                    }
                    p.read_field_end()?;
                }
                p.read_struct_end()?;
                alt.ok_or_else(||
                    ::fbthrift::ApplicationException::new(
                        ::fbthrift::ApplicationExceptionErrorCode::MissingResult,
                        format!("Empty union {}", "NumbersStreamExn"),
                    )
                    .into(),
                )
            }
        }

        #[derive(Clone, Debug)]
        pub enum NumbersResponseExn {
            #[doc(hidden)]
            Success(()),

            ApplicationException(::fbthrift::ApplicationException),
        }

        impl ::fbthrift::ExceptionInfo for NumbersResponseExn {
            fn exn_name(&self) -> &'static str {
                match self {
                    Self::Success(_) => panic!("ExceptionInfo::exn_name called on Success"),
                    Self::ApplicationException(aexn) => aexn.exn_name(),
                }
            }

            fn exn_value(&self) -> String {
                match self {
                    Self::Success(_) => panic!("ExceptionInfo::exn_value called on Success"),
                    Self::ApplicationException(aexn) => aexn.exn_value(),
                }
            }

            fn exn_is_declared(&self) -> bool {
                match self {
                    Self::Success(_) => panic!("ExceptionInfo::exn_is_declared called on Success"),
                    Self::ApplicationException(aexn) => aexn.exn_is_declared(),
                }
            }
        }

        impl ::fbthrift::ResultInfo for NumbersResponseExn {
            fn result_type(&self) -> ::fbthrift::ResultType {
                match self {
                    Self::Success(_) => ::fbthrift::ResultType::Return,
                    Self::ApplicationException(_aexn) => ::fbthrift::ResultType::Exception,
                }
            }
        }

        impl ::std::convert::From<::fbthrift::ApplicationException> for NumbersResponseExn {
            fn from(exn: ::fbthrift::ApplicationException) -> Self {
                Self::ApplicationException(exn)
            }
        }

        impl ::fbthrift::GetTType for NumbersResponseExn {
            const TTYPE: ::fbthrift::TType = ::fbthrift::TType::Void;
        }

        impl<P> ::fbthrift::Serialize<P> for NumbersResponseExn
        where
            P: ::fbthrift::ProtocolWriter,
        {
            fn write(&self, p: &mut P) {
                if let Self::ApplicationException(aexn) = self {
                    return aexn.write(p);
                }
                p.write_struct_begin("Numbers");
                match self {
                    Self::Success(_inner) => {
                        p.write_field_begin(
                            "Success",
                            ::fbthrift::TType::Void,
                            0i16,
                        );
                        p.write_field_end();
                    }
                    Self::ApplicationException(_) => unreachable!(),
                }
                p.write_field_stop();
                p.write_struct_end();
            }
        }

        impl<P> ::fbthrift::Deserialize<P> for NumbersResponseExn
        where
            P: ::fbthrift::ProtocolReader,
        {
            fn read(p: &mut P) -> ::anyhow::Result<Self> {
                static RETURNS: &[::fbthrift::Field] = &[
                    ::fbthrift::Field::new("Success", ::fbthrift::TType::Stream, 0),
                ];
                let _ = p.read_struct_begin(|_| ())?;
                let mut once = false;
                let mut alt = Self::Success(());
                loop {
                    let (_, fty, fid) = p.read_field_begin(|_| (), RETURNS)?;
                    match ((fty, fid as ::std::primitive::i32), once) {
                        ((::fbthrift::TType::Stop, _), _) => {
                            p.read_field_end()?;
                            break;
                        }
                        ((::fbthrift::TType::Void, 0i32), false) => {
                            once = true;
                            alt = Self::Success(::fbthrift::Deserialize::read(p)?);
                        }
                        ((ty, _id), false) => p.skip(ty)?,
                        ((badty, badid), true) => return ::std::result::Result::Err(::std::convert::From::from(
                            ::fbthrift::ApplicationException::new(
                                ::fbthrift::ApplicationExceptionErrorCode::ProtocolError,
                                format!(
                                    "unwanted extra union {} field ty {:?} id {}",
                                    "NumbersResponseExn",
                                    badty,
                                    badid,
                                ),
                            )
                        )),
                    }
                    p.read_field_end()?;
                }
                p.read_struct_end()?;
                ::std::result::Result::Ok(alt)
            }
        }

        pub enum NumbersExn {
            #[doc(hidden)]
            Success(    ::futures::stream::BoxStream<'static, ::std::result::Result<crate::types::number, crate::services::c::NumbersStreamExn>>
),
            ApplicationException(::fbthrift::ApplicationException),
        }

        impl ::std::convert::From<crate::errors::c::NumbersError> for NumbersExn {
            fn from(err: crate::errors::c::NumbersError) -> Self {
                match err {
                    crate::errors::c::NumbersError::ApplicationException(aexn) => NumbersExn::ApplicationException(aexn),
                    crate::errors::c::NumbersError::ThriftError(err) => NumbersExn::ApplicationException(::fbthrift::ApplicationException {
                        message: err.to_string(),
                        type_: ::fbthrift::ApplicationExceptionErrorCode::InternalError,
                    }),
                }
            }
        }

        impl ::std::convert::From<::fbthrift::ApplicationException> for NumbersExn {
            fn from(exn: ::fbthrift::ApplicationException) -> Self {
                Self::ApplicationException(exn)
            }
        }

        impl ::fbthrift::ExceptionInfo for NumbersExn {
            fn exn_name(&self) -> &'static str {
                match self {
                    Self::Success(_) => panic!("ExceptionInfo::exn_name called on Success"),
                    Self::ApplicationException(aexn) => aexn.exn_name(),
                }
            }

            fn exn_value(&self) -> String {
                match self {
                    Self::Success(_) => panic!("ExceptionInfo::exn_value called on Success"),
                    Self::ApplicationException(aexn) => aexn.exn_value(),
                }
            }

            fn exn_is_declared(&self) -> bool {
                match self {
                    Self::Success(_) => panic!("ExceptionInfo::exn_is_declared called on Success"),
                    Self::ApplicationException(aexn) => aexn.exn_is_declared(),
                }
            }
        }

        impl ::fbthrift::ResultInfo for NumbersExn {
            fn result_type(&self) -> ::fbthrift::ResultType {
                match self {
                    Self::Success(_) => ::fbthrift::ResultType::Return,
                    Self::ApplicationException(_aexn) => ::fbthrift::ResultType::Exception,
                }
            }
        }

        impl ::fbthrift::GetTType for NumbersExn {
            const TTYPE: ::fbthrift::TType = ::fbthrift::TType::Struct;
        }

        #[derive(Clone, Debug)]
        pub enum ThingExn {
            #[doc(hidden)]
            Success(::std::string::String),
            bang(crate::types::Bang),
            ApplicationException(::fbthrift::ApplicationException),
        }

        impl ::std::convert::From<crate::types::Bang> for ThingExn {
            fn from(exn: crate::types::Bang) -> Self {
                Self::bang(exn)
            }
        }

        impl ::std::convert::From<crate::errors::c::ThingError> for ThingExn {
            fn from(err: crate::errors::c::ThingError) -> Self {
                match err {
                    crate::errors::c::ThingError::bang(err) => ThingExn::bang(err),
                    crate::errors::c::ThingError::ApplicationException(aexn) => ThingExn::ApplicationException(aexn),
                    crate::errors::c::ThingError::ThriftError(err) => ThingExn::ApplicationException(::fbthrift::ApplicationException {
                        message: err.to_string(),
                        type_: ::fbthrift::ApplicationExceptionErrorCode::InternalError,
                    }),
                }
            }
        }

        impl ::std::convert::From<::fbthrift::ApplicationException> for ThingExn {
            fn from(exn: ::fbthrift::ApplicationException) -> Self {
                Self::ApplicationException(exn)
            }
        }

        impl ::fbthrift::ExceptionInfo for ThingExn {
            fn exn_name(&self) -> &'static str {
                match self {
                    Self::Success(_) => panic!("ExceptionInfo::exn_name called on Success"),
                    Self::ApplicationException(aexn) => aexn.exn_name(),
                    Self::bang(exn) => exn.exn_name(),
                }
            }

            fn exn_value(&self) -> String {
                match self {
                    Self::Success(_) => panic!("ExceptionInfo::exn_value called on Success"),
                    Self::ApplicationException(aexn) => aexn.exn_value(),
                    Self::bang(exn) => exn.exn_value(),
                }
            }

            fn exn_is_declared(&self) -> bool {
                match self {
                    Self::Success(_) => panic!("ExceptionInfo::exn_is_declared called on Success"),
                    Self::ApplicationException(aexn) => aexn.exn_is_declared(),
                    Self::bang(exn) => exn.exn_is_declared(),
                }
            }
        }

        impl ::fbthrift::ResultInfo for ThingExn {
            fn result_type(&self) -> ::fbthrift::ResultType {
                match self {
                    Self::Success(_) => ::fbthrift::ResultType::Return,
                    Self::ApplicationException(_aexn) => ::fbthrift::ResultType::Exception,
                    Self::bang(_exn) => fbthrift::ResultType::Error,
                }
            }
        }

        impl ::fbthrift::GetTType for ThingExn {
            const TTYPE: ::fbthrift::TType = ::fbthrift::TType::Struct;
        }

        impl<P> ::fbthrift::Serialize<P> for ThingExn
        where
            P: ::fbthrift::ProtocolWriter,
        {
            fn write(&self, p: &mut P) {
                if let Self::ApplicationException(aexn) = self {
                    return aexn.write(p);
                }
                p.write_struct_begin("Thing");
                match self {
                    Self::Success(inner) => {
                        p.write_field_begin(
                            "Success",
                            ::fbthrift::TType::String,
                            0i16,
                        );
                        inner.write(p);
                        p.write_field_end();
                    }
                    Self::bang(inner) => {
                        p.write_field_begin(
                            "bang",
                            ::fbthrift::TType::Struct,
                            1,
                        );
                        inner.write(p);
                        p.write_field_end();
                    }
                    Self::ApplicationException(_aexn) => unreachable!(),
                }
                p.write_field_stop();
                p.write_struct_end();
            }
        }

        impl<P> ::fbthrift::Deserialize<P> for ThingExn
        where
            P: ::fbthrift::ProtocolReader,
        {
            fn read(p: &mut P) -> ::anyhow::Result<Self> {
                static RETURNS: &[::fbthrift::Field] = &[
                    ::fbthrift::Field::new("Success", ::fbthrift::TType::String, 0),
                    ::fbthrift::Field::new("bang", ::fbthrift::TType::Struct, 1),
                ];
                let _ = p.read_struct_begin(|_| ())?;
                let mut once = false;
                let mut alt = ::std::option::Option::None;
                loop {
                    let (_, fty, fid) = p.read_field_begin(|_| (), RETURNS)?;
                    match ((fty, fid as ::std::primitive::i32), once) {
                        ((::fbthrift::TType::Stop, _), _) => {
                            p.read_field_end()?;
                            break;
                        }
                        ((::fbthrift::TType::String, 0i32), false) => {
                            once = true;
                            alt = ::std::option::Option::Some(Self::Success(::fbthrift::Deserialize::read(p)?));
                        }
                        ((::fbthrift::TType::Struct, 1), false) => {
                            once = true;
                            alt = ::std::option::Option::Some(Self::bang(::fbthrift::Deserialize::read(p)?));
                        }
                        ((ty, _id), false) => p.skip(ty)?,
                        ((badty, badid), true) => return ::std::result::Result::Err(::std::convert::From::from(
                            ::fbthrift::ApplicationException::new(
                                ::fbthrift::ApplicationExceptionErrorCode::ProtocolError,
                                format!(
                                    "unwanted extra union {} field ty {:?} id {}",
                                    "ThingExn",
                                    badty,
                                    badid,
                                ),
                            )
                        )),
                    }
                    p.read_field_end()?;
                }
                p.read_struct_end()?;
                alt.ok_or_else(||
                    ::fbthrift::ApplicationException::new(
                        ::fbthrift::ApplicationExceptionErrorCode::MissingResult,
                        format!("Empty union {}", "ThingExn"),
                    )
                    .into(),
                )
            }
        }
    }
}

/// Client implementation for each service in `module`.
pub mod client {

    pub struct CImpl<P, T, S = ::fbthrift::NoopSpawner> {
        transport: T,
        _phantom: ::std::marker::PhantomData<fn() -> (P, S)>,
    }

    impl<P, T, S> CImpl<P, T, S>
    where
        P: ::fbthrift::Protocol,
        T: ::fbthrift::Transport,
        P::Frame: ::fbthrift::Framing<DecBuf = ::fbthrift::FramingDecoded<T>>,
        ::fbthrift::ProtocolEncoded<P>: ::fbthrift::BufMutExt<Final = ::fbthrift::FramingEncodedFinal<T>>,
        P::Deserializer: ::std::marker::Send,
        S: ::fbthrift::help::Spawner,
    {
        pub fn new(
            transport: T,
        ) -> Self {
            Self {
                transport,
                _phantom: ::std::marker::PhantomData,
            }
        }

        pub fn transport(&self) -> &T {
            &self.transport
        }

        fn _f_impl(
            &self,
            rpc_options: T::RpcOptions,
        ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<(), crate::errors::c::FError>> {
            use ::const_cstr::const_cstr;
            use ::tracing::Instrument as _;
            use ::futures::FutureExt as _;

            const_cstr! {
                SERVICE_NAME = "C";
                SERVICE_METHOD_NAME = "C.f";
            }
            let args = self::Args_C_f {
                _phantom: ::std::marker::PhantomData,
            };

            let transport = self.transport();

            // need to do call setup outside of async block because T: Transport isn't Send
            let request_env = match ::fbthrift::help::serialize_request_envelope::<P, _>("f", &args) {
                ::std::result::Result::Ok(res) => res,
                ::std::result::Result::Err(err) => return ::futures::future::err(err.into()).boxed(),
            };

            let call = transport
                .call(SERVICE_NAME.as_cstr(), SERVICE_METHOD_NAME.as_cstr(), request_env, rpc_options)
                .instrument(::tracing::trace_span!("call", method = "C.f"));

            async move {
                let reply_env = call.await?;

                let de = P::deserializer(reply_env);
                let (res, _de): (::std::result::Result<crate::services::c::FExn, _>, _) =
                    ::fbthrift::help::async_deserialize_response_envelope::<P, _, S>(de).await?;

                let res = match res {
                    ::std::result::Result::Ok(exn) => ::std::convert::From::from(exn),
                    ::std::result::Result::Err(aexn) =>
                        ::std::result::Result::Err(crate::errors::c::FError::ApplicationException(aexn))
                };
                res
            }
            .instrument(::tracing::info_span!("stream", method = "C.f"))
            .boxed()
        }

        fn _numbers_impl(
            &self,
            rpc_options: T::RpcOptions,
        ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<::futures::stream::BoxStream<'static, ::std::result::Result<crate::types::number, crate::errors::c::NumbersStreamError>>, crate::errors::c::NumbersError>> {
            use ::const_cstr::const_cstr;
            use ::tracing::Instrument as _;
            use ::futures::FutureExt as _;
            use ::futures::StreamExt as _;
            use ::fbthrift::Deserialize as _;

            const_cstr! {
                SERVICE_NAME = "C";
                SERVICE_METHOD_NAME = "C.numbers";
            }
            let args = self::Args_C_numbers {
                _phantom: ::std::marker::PhantomData,
            };

            let transport = self.transport();

            // need to do call setup outside of async block because T: Transport isn't Send
            let request_env = match ::fbthrift::help::serialize_request_envelope::<P, _>("numbers", &args) {
                ::std::result::Result::Ok(res) => res,
                ::std::result::Result::Err(err) => return ::futures::future::err(err.into()).boxed(),
            };

            let call_stream = transport
                .call_stream(SERVICE_NAME.as_cstr(), SERVICE_METHOD_NAME.as_cstr(), request_env, rpc_options)
                .instrument(::tracing::trace_span!("call_stream", method = "C.numbers"));

            async move {
                let (initial, stream) = call_stream.await?;

                let new_stream = stream.then(|item_res| {
                    async move {
                        match item_res {
                            ::std::result::Result::Err(err) =>
                                ::std::result::Result::Err(crate::errors::c::NumbersStreamError::from(err)),
                            ::std::result::Result::Ok(item_enc) => {
                                let res = S::spawn(move || {
                                    match item_enc {
                                        ::fbthrift::ClientStreamElement::Reply(payload) => {
                                            let mut de = P::deserializer(payload);
                                            crate::services::c::NumbersStreamExn::read(&mut de)
                                        }
                                        ::fbthrift::ClientStreamElement::ApplicationEx(payload) => {
                                            let mut de = P::deserializer(payload);
                                            ::fbthrift::ApplicationException::read(&mut de).map(crate::services::c::NumbersStreamExn::ApplicationException)
                                        }
                                    }
                                }).await?;

                                let item: ::std::result::Result<crate::types::number, crate::errors::c::NumbersStreamError> =
                                    ::std::convert::From::from(res);
                                item
                            }
                        }
                    }
                })
                .boxed();

                let de = P::deserializer(initial);
                let res: crate::services::c::NumbersResponseExn =
                    ::fbthrift::help::async_deserialize_response_envelope::<P, _, S>(de).await?.0?;

                let initial: ::std::result::Result<(), crate::errors::c::NumbersError> =
                    ::std::convert::From::from(res);
                let res = initial.map(move |_| new_stream);
                res
            }
            .instrument(::tracing::info_span!("stream", method = "C.numbers"))
            .boxed()
        }

        fn _thing_impl(
            &self,
            arg_a: ::std::primitive::i32,
            arg_b: &::std::primitive::str,
            arg_c: &::std::collections::BTreeSet<::std::primitive::i32>,
            rpc_options: T::RpcOptions,
        ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<::std::string::String, crate::errors::c::ThingError>> {
            use ::const_cstr::const_cstr;
            use ::tracing::Instrument as _;
            use ::futures::FutureExt as _;

            const_cstr! {
                SERVICE_NAME = "C";
                SERVICE_METHOD_NAME = "C.thing";
            }
            let args = self::Args_C_thing {
                a: arg_a,
                b: arg_b,
                c: arg_c,
                _phantom: ::std::marker::PhantomData,
            };

            let transport = self.transport();

            // need to do call setup outside of async block because T: Transport isn't Send
            let request_env = match ::fbthrift::help::serialize_request_envelope::<P, _>("thing", &args) {
                ::std::result::Result::Ok(res) => res,
                ::std::result::Result::Err(err) => return ::futures::future::err(err.into()).boxed(),
            };

            let call = transport
                .call(SERVICE_NAME.as_cstr(), SERVICE_METHOD_NAME.as_cstr(), request_env, rpc_options)
                .instrument(::tracing::trace_span!("call", method = "C.thing"));

            async move {
                let reply_env = call.await?;

                let de = P::deserializer(reply_env);
                let (res, _de): (::std::result::Result<crate::services::c::ThingExn, _>, _) =
                    ::fbthrift::help::async_deserialize_response_envelope::<P, _, S>(de).await?;

                let res = match res {
                    ::std::result::Result::Ok(exn) => ::std::convert::From::from(exn),
                    ::std::result::Result::Err(aexn) =>
                        ::std::result::Result::Err(crate::errors::c::ThingError::ApplicationException(aexn))
                };
                res
            }
            .instrument(::tracing::info_span!("stream", method = "C.thing"))
            .boxed()
        }
    }

    #[doc = "Detailed overview of service"]
    pub trait C: ::std::marker::Send {
        #[doc = "Function doctext."]
        fn f(
            &self,
        ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<(), crate::errors::c::FError>>;

        #[doc = "Streaming function"]
        fn numbers(
            &self,
        ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<::futures::stream::BoxStream<'static, ::std::result::Result<crate::types::number, crate::errors::c::NumbersStreamError>>, crate::errors::c::NumbersError>>;

        #[doc = ""]
        fn thing(
            &self,
            arg_a: ::std::primitive::i32,
            arg_b: &::std::primitive::str,
            arg_c: &::std::collections::BTreeSet<::std::primitive::i32>,
        ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<::std::string::String, crate::errors::c::ThingError>>;
    }

    pub trait CExt<T>: C
    where
        T: ::fbthrift::Transport,
    {
        #[doc = "Function doctext."]
        fn f_with_rpc_opts(
            &self,
            rpc_options: T::RpcOptions,
        ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<(), crate::errors::c::FError>>;
        #[doc = "Streaming function"]
        fn numbers_with_rpc_opts(
            &self,
            rpc_options: T::RpcOptions,
        ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<::futures::stream::BoxStream<'static, ::std::result::Result<crate::types::number, crate::errors::c::NumbersStreamError>>, crate::errors::c::NumbersError>>;
        #[doc = ""]
        fn thing_with_rpc_opts(
            &self,
            arg_a: ::std::primitive::i32,
            arg_b: &::std::primitive::str,
            arg_c: &::std::collections::BTreeSet<::std::primitive::i32>,
            rpc_options: T::RpcOptions,
        ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<::std::string::String, crate::errors::c::ThingError>>;

        fn transport(&self) -> &T;
    }

    struct Args_C_f<'a> {
        _phantom: ::std::marker::PhantomData<&'a ()>,
    }

    impl<'a, P: ::fbthrift::ProtocolWriter> ::fbthrift::Serialize<P> for self::Args_C_f<'a> {
        #[inline]
        #[::tracing::instrument(skip_all, level = "trace", name = "serialize_args", fields(method = "C.f"))]
        fn write(&self, p: &mut P) {
            p.write_struct_begin("args");
            p.write_field_stop();
            p.write_struct_end();
        }
    }

    struct Args_C_numbers<'a> {
        _phantom: ::std::marker::PhantomData<&'a ()>,
    }

    impl<'a, P: ::fbthrift::ProtocolWriter> ::fbthrift::Serialize<P> for self::Args_C_numbers<'a> {
        #[inline]
        #[::tracing::instrument(skip_all, level = "trace", name = "serialize_args", fields(method = "C.numbers"))]
        fn write(&self, p: &mut P) {
            p.write_struct_begin("args");
            p.write_field_stop();
            p.write_struct_end();
        }
    }

    struct Args_C_thing<'a> {
        a: ::std::primitive::i32,
        b: &'a ::std::primitive::str,
        c: &'a ::std::collections::BTreeSet<::std::primitive::i32>,
        _phantom: ::std::marker::PhantomData<&'a ()>,
    }

    impl<'a, P: ::fbthrift::ProtocolWriter> ::fbthrift::Serialize<P> for self::Args_C_thing<'a> {
        #[inline]
        #[::tracing::instrument(skip_all, level = "trace", name = "serialize_args", fields(method = "C.thing"))]
        fn write(&self, p: &mut P) {
            p.write_struct_begin("args");
            p.write_field_begin("a", ::fbthrift::TType::I32, 1i16);
            ::fbthrift::Serialize::write(&self.a, p);
            p.write_field_end();
            p.write_field_begin("b", ::fbthrift::TType::String, 2i16);
            ::fbthrift::Serialize::write(&self.b, p);
            p.write_field_end();
            p.write_field_begin("c", ::fbthrift::TType::Set, 3i16);
            ::fbthrift::Serialize::write(&self.c, p);
            p.write_field_end();
            p.write_field_stop();
            p.write_struct_end();
        }
    }

    impl<P, T, S> C for CImpl<P, T, S>
    where
        P: ::fbthrift::Protocol,
        T: ::fbthrift::Transport,
        P::Frame: ::fbthrift::Framing<DecBuf = ::fbthrift::FramingDecoded<T>>,
        ::fbthrift::ProtocolEncoded<P>: ::fbthrift::BufMutExt<Final = ::fbthrift::FramingEncodedFinal<T>>,
        P::Deserializer: ::std::marker::Send,
        S: ::fbthrift::help::Spawner,
    {
        fn f(
            &self,
        ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<(), crate::errors::c::FError>> {
            let rpc_options = T::RpcOptions::default();
            self._f_impl(
                rpc_options,
            )
        }
        fn numbers(
            &self,
        ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<::futures::stream::BoxStream<'static, ::std::result::Result<crate::types::number, crate::errors::c::NumbersStreamError>>, crate::errors::c::NumbersError>> {
            let rpc_options = T::RpcOptions::default();
            self._numbers_impl(
                rpc_options,
            )
        }
        fn thing(
            &self,
            arg_a: ::std::primitive::i32,
            arg_b: &::std::primitive::str,
            arg_c: &::std::collections::BTreeSet<::std::primitive::i32>,
        ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<::std::string::String, crate::errors::c::ThingError>> {
            let rpc_options = T::RpcOptions::default();
            self._thing_impl(
                arg_a,
                arg_b,
                arg_c,
                rpc_options,
            )
        }
    }

    impl<P, T, S> CExt<T> for CImpl<P, T, S>
    where
        P: ::fbthrift::Protocol,
        T: ::fbthrift::Transport,
        P::Frame: ::fbthrift::Framing<DecBuf = ::fbthrift::FramingDecoded<T>>,
        ::fbthrift::ProtocolEncoded<P>: ::fbthrift::BufMutExt<Final = ::fbthrift::FramingEncodedFinal<T>>,
        P::Deserializer: ::std::marker::Send,
        S: ::fbthrift::help::Spawner,
    {
        fn f_with_rpc_opts(
            &self,
            rpc_options: T::RpcOptions,
        ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<(), crate::errors::c::FError>> {
            self._f_impl(
                rpc_options,
            )
        }
        fn numbers_with_rpc_opts(
            &self,
            rpc_options: T::RpcOptions,
        ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<::futures::stream::BoxStream<'static, ::std::result::Result<crate::types::number, crate::errors::c::NumbersStreamError>>, crate::errors::c::NumbersError>> {
            self._numbers_impl(
                rpc_options,
            )
        }
        fn thing_with_rpc_opts(
            &self,
            arg_a: ::std::primitive::i32,
            arg_b: &::std::primitive::str,
            arg_c: &::std::collections::BTreeSet<::std::primitive::i32>,
            rpc_options: T::RpcOptions,
        ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<::std::string::String, crate::errors::c::ThingError>> {
            self._thing_impl(
                arg_a,
                arg_b,
                arg_c,
                rpc_options,
            )
        }

        fn transport(&self) -> &T {
          self.transport()
        }
    }

    impl<'a, S> C for S
    where
        S: ::std::convert::AsRef<dyn C + 'a>,
        S: ::std::marker::Send,
    {
        fn f(
            &self,
        ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<(), crate::errors::c::FError>> {
            self.as_ref().f(
            )
        }
        fn numbers(
            &self,
        ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<::futures::stream::BoxStream<'static, ::std::result::Result<crate::types::number, crate::errors::c::NumbersStreamError>>, crate::errors::c::NumbersError>> {
            self.as_ref().numbers(
            )
        }
        fn thing(
            &self,
            arg_a: ::std::primitive::i32,
            arg_b: &::std::primitive::str,
            arg_c: &::std::collections::BTreeSet<::std::primitive::i32>,
        ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<::std::string::String, crate::errors::c::ThingError>> {
            self.as_ref().thing(
                arg_a,
                arg_b,
                arg_c,
            )
        }
    }

    impl<S, T> CExt<T> for S
    where
        S: ::std::convert::AsRef<dyn C + 'static>,
        S: ::std::convert::AsRef<dyn CExt<T> + 'static>,
        S: ::std::marker::Send,
        T: ::fbthrift::Transport,
    {
        fn f_with_rpc_opts(
            &self,
            rpc_options: T::RpcOptions,
        ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<(), crate::errors::c::FError>> {
            <Self as ::std::convert::AsRef<dyn CExt<T>>>::as_ref(self).f_with_rpc_opts(
                rpc_options,
            )
        }
        fn numbers_with_rpc_opts(
            &self,
            rpc_options: T::RpcOptions,
        ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<::futures::stream::BoxStream<'static, ::std::result::Result<crate::types::number, crate::errors::c::NumbersStreamError>>, crate::errors::c::NumbersError>> {
            <Self as ::std::convert::AsRef<dyn CExt<T>>>::as_ref(self).numbers_with_rpc_opts(
                rpc_options,
            )
        }
        fn thing_with_rpc_opts(
            &self,
            arg_a: ::std::primitive::i32,
            arg_b: &::std::primitive::str,
            arg_c: &::std::collections::BTreeSet<::std::primitive::i32>,
            rpc_options: T::RpcOptions,
        ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<::std::string::String, crate::errors::c::ThingError>> {
            <Self as ::std::convert::AsRef<dyn CExt<T>>>::as_ref(self).thing_with_rpc_opts(
                arg_a,
                arg_b,
                arg_c,
                rpc_options,
            )
        }

        fn transport(&self) -> &T {
            <dyn CExt<T> as CExt<T>>::transport(<Self as ::std::convert::AsRef<dyn CExt<T>>>::as_ref(self))
        }
    }

    #[derive(Clone)]
    pub struct make_C;

    /// To be called by user directly setting up a client. Avoids
    /// needing ClientFactory trait in scope, avoids unidiomatic
    /// make_Trait name.
    ///
    /// ```
    /// # const _: &str = stringify! {
    /// use bgs::client::BuckGraphService;
    ///
    /// let protocol = BinaryProtocol::new();
    /// let transport = HttpClient::new();
    /// let client = <dyn BuckGraphService>::new(protocol, transport);
    /// # };
    /// ```
    impl dyn C {
        pub fn new<P, T>(
            protocol: P,
            transport: T,
        ) -> ::std::sync::Arc<impl C + ::std::marker::Send + ::std::marker::Sync + 'static>
        where
            P: ::fbthrift::Protocol<Frame = T>,
            T: ::fbthrift::Transport,
            P::Deserializer: ::std::marker::Send,
        {
            let spawner = ::fbthrift::help::NoopSpawner;
            Self::with_spawner(protocol, transport, spawner)
        }

        pub fn with_spawner<P, T, S>(
            protocol: P,
            transport: T,
            spawner: S,
        ) -> ::std::sync::Arc<impl C + ::std::marker::Send + ::std::marker::Sync + 'static>
        where
            P: ::fbthrift::Protocol<Frame = T>,
            T: ::fbthrift::Transport,
            P::Deserializer: ::std::marker::Send,
            S: ::fbthrift::help::Spawner,
        {
            let _ = protocol;
            let _ = spawner;
            ::std::sync::Arc::new(CImpl::<P, T, S>::new(transport))
        }
    }

    impl<T> dyn CExt<T>
    where
        T: ::fbthrift::Transport,
    {
        pub fn new<P>(
            protocol: P,
            transport: T,
        ) -> ::std::sync::Arc<impl CExt<T> + ::std::marker::Send + ::std::marker::Sync + 'static>
        where
            P: ::fbthrift::Protocol<Frame = T>,
            P::Deserializer: ::std::marker::Send,
        {
            let spawner = ::fbthrift::help::NoopSpawner;
            Self::with_spawner(protocol, transport, spawner)
        }

        pub fn with_spawner<P, S>(
            protocol: P,
            transport: T,
            spawner: S,
        ) -> ::std::sync::Arc<impl CExt<T> + ::std::marker::Send + ::std::marker::Sync + 'static>
        where
            P: ::fbthrift::Protocol<Frame = T>,
            P::Deserializer: ::std::marker::Send,
            S: ::fbthrift::help::Spawner,
        {
            let _ = protocol;
            let _ = spawner;
            ::std::sync::Arc::new(CImpl::<P, T, S>::new(transport))
        }
    }

    pub type CDynClient = <make_C as ::fbthrift::ClientFactory>::Api;
    pub type CClient = ::std::sync::Arc<CDynClient>;

    /// The same thing, but to be called from generic contexts where we are
    /// working with a type parameter `C: ClientFactory` to produce clients.
    impl ::fbthrift::ClientFactory for make_C {
        type Api = dyn C + ::std::marker::Send + ::std::marker::Sync + 'static;

        fn with_spawner<P, T, S>(protocol: P, transport: T, spawner: S) -> ::std::sync::Arc<Self::Api>
        where
            P: ::fbthrift::Protocol<Frame = T>,
            T: ::fbthrift::Transport,
            P::Deserializer: ::std::marker::Send,
            S: ::fbthrift::help::Spawner,
        {
            <dyn C>::with_spawner(protocol, transport, spawner)
        }
    }

}

/// Server definitions for `module`.
pub mod server {
    #[doc = "Detailed overview of service"]
    #[::async_trait::async_trait]
    pub trait C: ::std::marker::Send + ::std::marker::Sync + 'static {
        #[doc = "Function doctext."]
        async fn f(
            &self,
        ) -> ::std::result::Result<(), crate::services::c::FExn> {
            ::std::result::Result::Err(crate::services::c::FExn::ApplicationException(
                ::fbthrift::ApplicationException::unimplemented_method(
                    "C",
                    "f",
                ),
            ))
        }
        #[doc = "Streaming function"]
        async fn numbers(
            &self,
        ) -> ::std::result::Result<    ::futures::stream::BoxStream<'static, ::std::result::Result<crate::types::number, crate::services::c::NumbersStreamExn>>
, crate::services::c::NumbersExn> {
            ::std::result::Result::Err(crate::services::c::NumbersExn::ApplicationException(
                ::fbthrift::ApplicationException::unimplemented_method(
                    "C",
                    "numbers",
                ),
            ))
        }
        #[doc = ""]
        async fn thing(
            &self,
            _a: ::std::primitive::i32,
            _b: ::std::string::String,
            _c: ::std::collections::BTreeSet<::std::primitive::i32>,
        ) -> ::std::result::Result<::std::string::String, crate::services::c::ThingExn> {
            ::std::result::Result::Err(crate::services::c::ThingExn::ApplicationException(
                ::fbthrift::ApplicationException::unimplemented_method(
                    "C",
                    "thing",
                ),
            ))
        }
    }

    #[::async_trait::async_trait]
    impl<T> C for ::std::boxed::Box<T>
    where
        T: C + Send + Sync + ?Sized,
    {
        async fn f(
            &self,
        ) -> ::std::result::Result<(), crate::services::c::FExn> {
            (**self).f(
            ).await
        }
        async fn numbers(
            &self,
        ) -> ::std::result::Result<    ::futures::stream::BoxStream<'static, ::std::result::Result<crate::types::number, crate::services::c::NumbersStreamExn>>
, crate::services::c::NumbersExn> {
            (**self).numbers(
            ).await
        }
        async fn thing(
            &self,
            a: ::std::primitive::i32,
            b: ::std::string::String,
            c: ::std::collections::BTreeSet<::std::primitive::i32>,
        ) -> ::std::result::Result<::std::string::String, crate::services::c::ThingExn> {
            (**self).thing(
                a,
                b,
                c,
            ).await
        }
    }

    /// Processor for C's methods.
    #[derive(Clone, Debug)]
    pub struct CProcessor<P, H, R, RS> {
        service: H,
        supa: ::fbthrift::NullServiceProcessor<P, R, RS>,
        _phantom: ::std::marker::PhantomData<(P, H, R, RS)>,
    }

    struct Args_C_f {
    }
    impl<P: ::fbthrift::ProtocolReader> ::fbthrift::Deserialize<P> for self::Args_C_f {
        #[inline]
        #[::tracing::instrument(skip_all, level = "trace", name = "deserialize_args", fields(method = "C.f"))]
        fn read(p: &mut P) -> ::anyhow::Result<Self> {
            static ARGS: &[::fbthrift::Field] = &[
            ];
            let _ = p.read_struct_begin(|_| ())?;
            loop {
                let (_, fty, fid) = p.read_field_begin(|_| (), ARGS)?;
                match (fty, fid as ::std::primitive::i32) {
                    (::fbthrift::TType::Stop, _) => break,
                    (fty, _) => p.skip(fty)?,
                }
                p.read_field_end()?;
            }
            p.read_struct_end()?;
            ::std::result::Result::Ok(Self {
            })
        }
    }

    struct Args_C_numbers {
    }
    impl<P: ::fbthrift::ProtocolReader> ::fbthrift::Deserialize<P> for self::Args_C_numbers {
        #[inline]
        #[::tracing::instrument(skip_all, level = "trace", name = "deserialize_args", fields(method = "C.numbers"))]
        fn read(p: &mut P) -> ::anyhow::Result<Self> {
            static ARGS: &[::fbthrift::Field] = &[
            ];
            let _ = p.read_struct_begin(|_| ())?;
            loop {
                let (_, fty, fid) = p.read_field_begin(|_| (), ARGS)?;
                match (fty, fid as ::std::primitive::i32) {
                    (::fbthrift::TType::Stop, _) => break,
                    (fty, _) => p.skip(fty)?,
                }
                p.read_field_end()?;
            }
            p.read_struct_end()?;
            ::std::result::Result::Ok(Self {
            })
        }
    }

    struct Args_C_thing {
        a: ::std::primitive::i32,
        b: ::std::string::String,
        c: ::std::collections::BTreeSet<::std::primitive::i32>,
    }
    impl<P: ::fbthrift::ProtocolReader> ::fbthrift::Deserialize<P> for self::Args_C_thing {
        #[inline]
        #[::tracing::instrument(skip_all, level = "trace", name = "deserialize_args", fields(method = "C.thing"))]
        fn read(p: &mut P) -> ::anyhow::Result<Self> {
            static ARGS: &[::fbthrift::Field] = &[
                ::fbthrift::Field::new("a", ::fbthrift::TType::I32, 1),
                ::fbthrift::Field::new("b", ::fbthrift::TType::String, 2),
                ::fbthrift::Field::new("c", ::fbthrift::TType::Set, 3),
            ];
            let mut field_a = ::std::option::Option::None;
            let mut field_b = ::std::option::Option::None;
            let mut field_c = ::std::option::Option::None;
            let _ = p.read_struct_begin(|_| ())?;
            loop {
                let (_, fty, fid) = p.read_field_begin(|_| (), ARGS)?;
                match (fty, fid as ::std::primitive::i32) {
                    (::fbthrift::TType::Stop, _) => break,
                    (::fbthrift::TType::I32, 1) => field_a = ::std::option::Option::Some(::fbthrift::Deserialize::read(p)?),
                    (::fbthrift::TType::String, 2) => field_b = ::std::option::Option::Some(::fbthrift::Deserialize::read(p)?),
                    (::fbthrift::TType::Set, 3) => field_c = ::std::option::Option::Some(::fbthrift::Deserialize::read(p)?),
                    (fty, _) => p.skip(fty)?,
                }
                p.read_field_end()?;
            }
            p.read_struct_end()?;
            ::std::result::Result::Ok(Self {
                a: field_a.ok_or_else(|| ::anyhow::anyhow!("`{}` missing arg `{}`", "C.thing", "a"))?,
                b: field_b.ok_or_else(|| ::anyhow::anyhow!("`{}` missing arg `{}`", "C.thing", "b"))?,
                c: field_c.ok_or_else(|| ::anyhow::anyhow!("`{}` missing arg `{}`", "C.thing", "c"))?,
            })
        }
    }

    impl<P, H, R, RS> CProcessor<P, H, R, RS>
    where
        P: ::fbthrift::Protocol + ::std::marker::Send + ::std::marker::Sync + 'static,
        P::Frame: ::std::marker::Send + 'static,
        P::Deserializer: ::std::marker::Send,
        H: C,
        R: ::fbthrift::RequestContext<Name = ::std::ffi::CStr> + ::std::marker::Send + ::std::marker::Sync + 'static,
        RS: ::fbthrift::ReplyState<P::Frame, RequestContext = R> + ::std::marker::Send + ::std::marker::Sync + 'static,
        <R as ::fbthrift::RequestContext>::ContextStack: ::fbthrift::ContextStack<Name = R::Name, Frame = <P as ::fbthrift::Protocol>::Frame>
            + ::std::marker::Send + ::std::marker::Sync,
        ::fbthrift::ProtocolDecoded<P>: ::std::clone::Clone,
        ::fbthrift::ProtocolEncodedFinal<P>: ::std::clone::Clone + ::fbthrift::BufExt,
    {
        pub fn new(service: H) -> Self {
            Self {
                service,
                supa: ::fbthrift::NullServiceProcessor::new(),
                _phantom: ::std::marker::PhantomData,
            }
        }

        pub fn into_inner(self) -> H {
            self.service
        }

        #[::tracing::instrument(skip_all, name = "handler", fields(method = "C.f"))]
        async fn handle_f<'a>(
            &'a self,
            p: &'a mut P::Deserializer,
            req: ::fbthrift::ProtocolDecoded<P>,
            req_ctxt: &R,
            reply_state: ::std::sync::Arc<::std::sync::Mutex<RS>>,
            _seqid: ::std::primitive::u32,
        ) -> ::anyhow::Result<()> {
            use ::const_cstr::const_cstr;
            use ::futures::FutureExt as _;

            const_cstr! {
                SERVICE_NAME = "C";
                METHOD_NAME = "f";
                SERVICE_METHOD_NAME = "C.f";
            }
            let mut ctx_stack = req_ctxt.get_context_stack(
                SERVICE_NAME.as_cstr(),
                SERVICE_METHOD_NAME.as_cstr(),
            )?;
            ::fbthrift::ContextStack::pre_read(&mut ctx_stack)?;
            let _args: self::Args_C_f = ::fbthrift::Deserialize::read(p)?;
            let bytes_read = ::fbthrift::help::buf_len(&req)?;
            ::fbthrift::ContextStack::on_read_data(&mut ctx_stack, ::fbthrift::SerializedMessage {
                protocol: P::PROTOCOL_ID,
                method_name: METHOD_NAME.as_cstr(),
                buffer: req,
            })?;
            ::fbthrift::ContextStack::post_read(&mut ctx_stack, bytes_read)?;

            let res = ::std::panic::AssertUnwindSafe(
                self.service.f(
                )
            )
            .catch_unwind()
            .await;

            // nested results - panic catch on the outside, method on the inside
            let res = match res {
                ::std::result::Result::Ok(::std::result::Result::Ok(res)) => {
                    ::tracing::trace!(method = "C.f", "success");
                    crate::services::c::FExn::Success(res)
                }
                ::std::result::Result::Ok(::std::result::Result::Err(crate::services::c::FExn::Success(_))) => {
                    panic!(
                        "{} attempted to return success via error",
                        "f",
                    )
                }
                ::std::result::Result::Ok(::std::result::Result::Err(exn)) => {
                    ::tracing::info!(method = "C.f", exception = ?exn);
                    exn
                }
                ::std::result::Result::Err(exn) => {
                    let aexn = ::fbthrift::ApplicationException::handler_panic("C.f", exn);
                    ::tracing::error!(method = "C.f", panic = ?aexn);
                    crate::services::c::FExn::ApplicationException(aexn)
                }
            };

            let env = ::fbthrift::help::serialize_result_envelope::<P, R, _>(
                "f",
                METHOD_NAME.as_cstr(),
                _seqid,
                req_ctxt,
                &mut ctx_stack,
                res
            )?;
            reply_state.lock().unwrap().send_reply(env);
            Ok(())
        }

        #[::tracing::instrument(skip_all, name = "handler", fields(method = "C.numbers"))]
        async fn handle_numbers<'a>(
            &'a self,
            p: &'a mut P::Deserializer,
            req: ::fbthrift::ProtocolDecoded<P>,
            req_ctxt: &R,
            reply_state: ::std::sync::Arc<::std::sync::Mutex<RS>>,
            _seqid: ::std::primitive::u32,
        ) -> ::anyhow::Result<()> {
            use ::const_cstr::const_cstr;
            use ::futures::FutureExt as _;

            const_cstr! {
                SERVICE_NAME = "C";
                METHOD_NAME = "numbers";
                SERVICE_METHOD_NAME = "C.numbers";
            }
            let mut ctx_stack = req_ctxt.get_context_stack(
                SERVICE_NAME.as_cstr(),
                SERVICE_METHOD_NAME.as_cstr(),
            )?;
            ::fbthrift::ContextStack::pre_read(&mut ctx_stack)?;
            let _args: self::Args_C_numbers = ::fbthrift::Deserialize::read(p)?;
            let bytes_read = ::fbthrift::help::buf_len(&req)?;
            ::fbthrift::ContextStack::on_read_data(&mut ctx_stack, ::fbthrift::SerializedMessage {
                protocol: P::PROTOCOL_ID,
                method_name: METHOD_NAME.as_cstr(),
                buffer: req,
            })?;
            ::fbthrift::ContextStack::post_read(&mut ctx_stack, bytes_read)?;

            let res = ::std::panic::AssertUnwindSafe(
                self.service.numbers(
                )
            )
            .catch_unwind()
            .await;

            // nested results - panic catch on the outside, method on the inside
            let res = match res {
                ::std::result::Result::Ok(::std::result::Result::Ok(res)) => {
                    ::tracing::trace!(method = "C.numbers", "success");
                    crate::services::c::NumbersExn::Success(res)
                }
                ::std::result::Result::Ok(::std::result::Result::Err(crate::services::c::NumbersExn::Success(_))) => {
                    panic!(
                        "{} attempted to return success via error",
                        "numbers",
                    )
                }
                ::std::result::Result::Ok(::std::result::Result::Err(exn)) => {
                    exn
                }
                ::std::result::Result::Err(exn) => {
                    let aexn = ::fbthrift::ApplicationException::handler_panic("C.numbers", exn);
                    ::tracing::error!(method = "C.numbers", panic = ?aexn);
                    crate::services::c::NumbersExn::ApplicationException(aexn)
                }
            };

            use ::futures::StreamExt as _;

            let (response, stream) = match res {
                crate::services::c::NumbersExn::Success(res) => {
                    let response = crate::services::c::NumbersResponseExn::Success(());
                    let stream = res;

                    let stream = ::std::panic::AssertUnwindSafe(stream)
                        .catch_unwind()
                        .map(|item| {
                            match item {
                                ::std::result::Result::Ok(::std::result::Result::Ok(res)) => {
                                    let item = crate::services::c::NumbersStreamExn::Success(res);
                                    match ::fbthrift::help::serialize_stream_item::<P, _>(item) {
                                        Ok(payload) => ::fbthrift::SerializedStreamElement::Success(payload),
                                        Err(err) => {
                                            tracing::error!(?err, method="C.numbers", "Failed to serialize success response");
                                            ::fbthrift::SerializedStreamElement::SerializationError(err)
                                        },
                                    }
                                }
                                ::std::result::Result::Ok(::std::result::Result::Err(crate::services::c::NumbersStreamExn::Success(_))) => {
                                    panic!("{} attempted to return success via error", "numbers");
                                }
                                ::std::result::Result::Ok(::std::result::Result::Err(crate::services::c::NumbersStreamExn::ApplicationException(aexn))) => {
                                    tracing::info!(?aexn, method="C.numbers", "Streaming ApplicationException");
                                    ::fbthrift::SerializedStreamElement::ApplicationException(aexn)
                                }
                                ::std::result::Result::Err(exn) => {
                                    tracing::error!(?exn, method="C.numbers", "Streaming unwind");
                                    let aexn = ::fbthrift::ApplicationException::handler_panic("C.numbers", exn);
                                    ::fbthrift::SerializedStreamElement::ApplicationException(aexn)
                                }
                            }
                        })
                        .boxed();
                    (response, Some(stream))
                },
                crate::services::c::NumbersExn::ApplicationException(aexn)=> {
                    let response = crate::services::c::NumbersResponseExn::ApplicationException(aexn);
                    (response, None)
                },
            };

            let response = ::fbthrift::help::serialize_result_envelope::<P, R, _>(
                        "numbers",
                        METHOD_NAME.as_cstr(),
                        _seqid,
                        req_ctxt,
                        &mut ctx_stack,
                        response
                    )?;

            let _ = reply_state.lock().unwrap().send_stream_reply(response, stream, P::PROTOCOL_ID);
            Ok(())
        }

        #[::tracing::instrument(skip_all, name = "handler", fields(method = "C.thing"))]
        async fn handle_thing<'a>(
            &'a self,
            p: &'a mut P::Deserializer,
            req: ::fbthrift::ProtocolDecoded<P>,
            req_ctxt: &R,
            reply_state: ::std::sync::Arc<::std::sync::Mutex<RS>>,
            _seqid: ::std::primitive::u32,
        ) -> ::anyhow::Result<()> {
            use ::const_cstr::const_cstr;
            use ::futures::FutureExt as _;

            const_cstr! {
                SERVICE_NAME = "C";
                METHOD_NAME = "thing";
                SERVICE_METHOD_NAME = "C.thing";
            }
            let mut ctx_stack = req_ctxt.get_context_stack(
                SERVICE_NAME.as_cstr(),
                SERVICE_METHOD_NAME.as_cstr(),
            )?;
            ::fbthrift::ContextStack::pre_read(&mut ctx_stack)?;
            let _args: self::Args_C_thing = ::fbthrift::Deserialize::read(p)?;
            let bytes_read = ::fbthrift::help::buf_len(&req)?;
            ::fbthrift::ContextStack::on_read_data(&mut ctx_stack, ::fbthrift::SerializedMessage {
                protocol: P::PROTOCOL_ID,
                method_name: METHOD_NAME.as_cstr(),
                buffer: req,
            })?;
            ::fbthrift::ContextStack::post_read(&mut ctx_stack, bytes_read)?;

            let res = ::std::panic::AssertUnwindSafe(
                self.service.thing(
                    _args.a,
                    _args.b,
                    _args.c,
                )
            )
            .catch_unwind()
            .await;

            // nested results - panic catch on the outside, method on the inside
            let res = match res {
                ::std::result::Result::Ok(::std::result::Result::Ok(res)) => {
                    ::tracing::trace!(method = "C.thing", "success");
                    crate::services::c::ThingExn::Success(res)
                }
                ::std::result::Result::Ok(::std::result::Result::Err(crate::services::c::ThingExn::Success(_))) => {
                    panic!(
                        "{} attempted to return success via error",
                        "thing",
                    )
                }
                ::std::result::Result::Ok(::std::result::Result::Err(exn)) => {
                    ::tracing::info!(method = "C.thing", exception = ?exn);
                    exn
                }
                ::std::result::Result::Err(exn) => {
                    let aexn = ::fbthrift::ApplicationException::handler_panic("C.thing", exn);
                    ::tracing::error!(method = "C.thing", panic = ?aexn);
                    crate::services::c::ThingExn::ApplicationException(aexn)
                }
            };

            let env = ::fbthrift::help::serialize_result_envelope::<P, R, _>(
                "thing",
                METHOD_NAME.as_cstr(),
                _seqid,
                req_ctxt,
                &mut ctx_stack,
                res
            )?;
            reply_state.lock().unwrap().send_reply(env);
            Ok(())
        }
    }

    #[::async_trait::async_trait]
    impl<P, H, R, RS> ::fbthrift::ServiceProcessor<P> for CProcessor<P, H, R, RS>
    where
        P: ::fbthrift::Protocol + ::std::marker::Send + ::std::marker::Sync + 'static,
        P::Deserializer: ::std::marker::Send,
        H: C,
        P::Frame: ::std::marker::Send + 'static,
        R: ::fbthrift::RequestContext<Name = ::std::ffi::CStr> + ::std::marker::Send + ::std::marker::Sync + 'static,
        <R as ::fbthrift::RequestContext>::ContextStack: ::fbthrift::ContextStack<Name = R::Name, Frame = <P as ::fbthrift::Protocol>::Frame>
            + ::std::marker::Send + ::std::marker::Sync + 'static,
        RS: ::fbthrift::ReplyState<P::Frame, RequestContext = R> + ::std::marker::Send + ::std::marker::Sync + 'static,
        ::fbthrift::ProtocolDecoded<P>: ::std::clone::Clone,
        ::fbthrift::ProtocolEncodedFinal<P>: ::std::clone::Clone + ::fbthrift::BufExt,
    {
        type RequestContext = R;
        type ReplyState = RS;

        #[inline]
        fn method_idx(&self, name: &[::std::primitive::u8]) -> ::std::result::Result<::std::primitive::usize, ::fbthrift::ApplicationException> {
            match name {
                b"f" => ::std::result::Result::Ok(0usize),
                b"numbers" => ::std::result::Result::Ok(1usize),
                b"thing" => ::std::result::Result::Ok(2usize),
                _ => ::std::result::Result::Err(::fbthrift::ApplicationException::unknown_method()),
            }
        }

        #[allow(clippy::match_single_binding)]
        async fn handle_method(
            &self,
            idx: ::std::primitive::usize,
            _p: &mut P::Deserializer,
            _req: ::fbthrift::ProtocolDecoded<P>,
            _req_ctxt: &R,
            _reply_state: ::std::sync::Arc<::std::sync::Mutex<RS>>,
            _seqid: ::std::primitive::u32,
        ) -> ::anyhow::Result<()> {
            match idx {
                0usize => {
                    self.handle_f(_p, _req, _req_ctxt, _reply_state, _seqid).await
                }
                1usize => {
                    self.handle_numbers(_p, _req, _req_ctxt, _reply_state, _seqid).await
                }
                2usize => {
                    self.handle_thing(_p, _req, _req_ctxt, _reply_state, _seqid).await
                }
                bad => panic!(
                    "{}: unexpected method idx {}",
                    "CProcessor",
                    bad
                ),
            }
        }

        #[allow(clippy::match_single_binding)]
        #[inline]
        fn create_interaction_idx(&self, name: &str) -> ::anyhow::Result<::std::primitive::usize> {
            match name {
                _ => ::anyhow::bail!("Unknown interaction"),
            }
        }

        #[allow(clippy::match_single_binding)]
        fn handle_create_interaction(
            &self,
            idx: ::std::primitive::usize,
        ) -> ::anyhow::Result<
            ::std::sync::Arc<dyn ::fbthrift::ThriftService<P::Frame, Handler = (), RequestContext = Self::RequestContext, ReplyState = Self::ReplyState> + ::std::marker::Send + 'static>
        > {
            match idx {
                bad => panic!(
                    "{}: unexpected method idx {}",
                    "CProcessor",
                    bad
                ),
            }
        }

        async fn handle_on_termination(&self) {
        }
    }

    #[::async_trait::async_trait]
    impl<P, H, R, RS> ::fbthrift::ThriftService<P::Frame> for CProcessor<P, H, R, RS>
    where
        P: ::fbthrift::Protocol + ::std::marker::Send + ::std::marker::Sync + 'static,
        P::Deserializer: ::std::marker::Send,
        P::Frame: ::std::marker::Send + 'static,
        H: C,
        R: ::fbthrift::RequestContext<Name = ::std::ffi::CStr> + ::std::marker::Send + ::std::marker::Sync + 'static,
        <R as ::fbthrift::RequestContext>::ContextStack: ::fbthrift::ContextStack<Name = R::Name, Frame = <P as ::fbthrift::Protocol>::Frame>
            + ::std::marker::Send + ::std::marker::Sync + 'static,
        RS: ::fbthrift::ReplyState<P::Frame, RequestContext = R> + ::std::marker::Send + ::std::marker::Sync + 'static,
        ::fbthrift::ProtocolDecoded<P>: ::std::clone::Clone,
        ::fbthrift::ProtocolEncodedFinal<P>: ::std::clone::Clone + ::fbthrift::BufExt,
    {
        type Handler = H;
        type RequestContext = R;
        type ReplyState = RS;

        #[tracing::instrument(level="trace", skip_all, fields(service = "C"))]
        async fn call(
            &self,
            req: ::fbthrift::ProtocolDecoded<P>,
            req_ctxt: &R,
            reply_state: ::std::sync::Arc<::std::sync::Mutex<RS>>,
        ) -> ::anyhow::Result<()> {
            use ::fbthrift::{ProtocolReader as _, ServiceProcessor as _};
            let mut p = P::deserializer(req.clone());
            let (idx, mty, seqid) = p.read_message_begin(|name| self.method_idx(name))?;
            if mty != ::fbthrift::MessageType::Call {
                return ::std::result::Result::Err(::std::convert::From::from(::fbthrift::ApplicationException::new(
                    ::fbthrift::ApplicationExceptionErrorCode::InvalidMessageType,
                    format!("message type {:?} not handled", mty)
                )));
            }
            let idx = match idx {
                ::std::result::Result::Ok(idx) => idx,
                ::std::result::Result::Err(_) => {
                    return self.supa.call(req, req_ctxt, reply_state).await;
                }
            };
            self.handle_method(idx, &mut p, req, req_ctxt, reply_state, seqid).await?;
            p.read_message_end()?;

            Ok(())
        }

        fn create_interaction(
            &self,
            name: &str,
        ) -> ::anyhow::Result<
            ::std::sync::Arc<dyn ::fbthrift::ThriftService<P::Frame, Handler = (), RequestContext = R, ReplyState = RS> + ::std::marker::Send + 'static>
        > {
            use ::fbthrift::{ServiceProcessor as _};
            let idx = self.create_interaction_idx(name);
            let idx = match idx {
                ::anyhow::Result::Ok(idx) => idx,
                ::anyhow::Result::Err(_) => {
                    return self.supa.create_interaction(name);
                }
            };
            self.handle_create_interaction(idx)
        }

        fn get_method_names(&self) -> &'static [&'static str] {
            &[
                // from C
                "f",
                "numbers",
                "thing",
            ]
        }

        async fn on_termination(&self) {
            use ::fbthrift::{ServiceProcessor as _};
            self.handle_on_termination().await
        }
    }

    /// Construct a new instance of a C service.
    ///
    /// This is called when a new instance of a Thrift service Processor
    /// is needed for a particular Thrift protocol.
    #[::tracing::instrument(level="debug", skip_all, fields(proto = ?proto))]
    pub fn make_C_server<F, H, R, RS>(
        proto: ::fbthrift::ProtocolID,
        handler: H,
    ) -> ::std::result::Result<::std::boxed::Box<dyn ::fbthrift::ThriftService<F, Handler = H, RequestContext = R, ReplyState = RS> + ::std::marker::Send + 'static>, ::fbthrift::ApplicationException>
    where
        F: ::fbthrift::Framing + ::std::marker::Send + ::std::marker::Sync + 'static,
        H: C,
        R: ::fbthrift::RequestContext<Name = ::std::ffi::CStr> + ::std::marker::Send + ::std::marker::Sync + 'static,
        <R as ::fbthrift::RequestContext>::ContextStack: ::fbthrift::ContextStack<Name = R::Name, Frame = F> + ::std::marker::Send + ::std::marker::Sync + 'static,
        RS: ::fbthrift::ReplyState<F, RequestContext = R> + ::std::marker::Send + ::std::marker::Sync + 'static,
        ::fbthrift::FramingDecoded<F>: ::std::clone::Clone,
        ::fbthrift::FramingEncodedFinal<F>: ::std::clone::Clone + ::fbthrift::BufExt,
    {
        match proto {
            ::fbthrift::ProtocolID::BinaryProtocol => {
                ::std::result::Result::Ok(::std::boxed::Box::new(CProcessor::<::fbthrift::BinaryProtocol<F>, H, R, RS>::new(handler)))
            }
            ::fbthrift::ProtocolID::CompactProtocol => {
                ::std::result::Result::Ok(::std::boxed::Box::new(CProcessor::<::fbthrift::CompactProtocol<F>, H, R, RS>::new(handler)))
            }
            bad => {
                ::tracing::error!(method = "C.", invalid_protocol = ?bad);
                ::std::result::Result::Err(::fbthrift::ApplicationException::invalid_protocol(bad))
            }
        }
    }
}

/// Client mocks. For every service, a struct mock::TheService that implements
/// client::TheService.
///
/// As an example of the generated API, for the following thrift service:
///
/// ```thrift
/// service MyService {
///     FunctionResponse myFunction(
///         1: FunctionRequest request,
///     ) throws {
///         1: StorageException s,
///         2: NotFoundException n,
///     ),
///
///     // other functions
/// }
/// ```
///
/// we would end up with this mock object under crate::mock::MyService:
///
/// ```
/// # const _: &str = stringify! {
/// impl crate::client::MyService for MyService<'mock> {...}
///
/// pub struct MyService<'mock> {
///     pub myFunction: myFunction<'mock>,
///     // ...
/// }
///
/// impl dyn crate::client::MyService {
///     pub fn mock<'mock>() -> MyService<'mock>;
/// }
///
/// impl myFunction<'mock> {
///     // directly return the given success response
///     pub fn ret(&self, value: FunctionResponse);
///
///     // invoke closure to compute success response
///     pub fn mock(
///         &self,
///         mock: impl FnMut(FunctionRequest) -> FunctionResponse + Send + Sync + 'mock,
///     );
///
///     // invoke closure to compute response
///     pub fn mock_result(
///         &self,
///         mock: impl FnMut(FunctionRequest) -> Result<FunctionResponse, crate::services::MyService::MyFunctionExn> + Send + Sync + 'mock,
///     );
///
///     // return one of the function's declared exceptions
///     pub fn throw<E>(&self, exception: E)
///     where
///         E: Clone + Into<crate::services::MyService::MyFunctionExn> + Send + Sync + 'mock;
/// }
///
/// impl From<StorageException> for MyFunctionExn {...}
/// impl From<NotFoundException> for MyFunctionExn {...}
/// # };
/// ```
///
/// The intended usage from a test would be:
///
/// ```
/// # const _: &str = stringify! {
/// use std::sync::Arc;
/// use thrift_if::client::MyService;
///
/// #[test]
/// fn test_my_client() {
///     let mock = Arc::new(<dyn MyService>::mock());
///
///     // directly return a success response
///     let resp = FunctionResponse {...};
///     mock.myFunction.ret(resp);
///
///     // or give a closure to compute the success response
///     mock.myFunction.mock(|request| FunctionResponse {...});
///
///     // or throw one of the function's exceptions
///     mock.myFunction.throw(StorageException::ItFailed);
///
///     // or compute a Result (useful if your exceptions aren't Clone)
///     mock.myFunction.mock_result(|request| Err(...));
///
///     let out = do_the_thing(mock).wait().unwrap();
///     assert!(out.what_i_expected());
/// }
///
/// fn do_the_thing(
///     client: Arc<dyn MyService + Send + Sync + 'static>,
/// ) -> impl Future<Item = Out> {...}
/// # };
/// ```
pub mod mock {
    pub struct C<'mock> {
        pub f: r#impl::c::f<'mock>,
        pub numbers: r#impl::c::numbers<'mock>,
        pub thing: r#impl::c::thing<'mock>,
        _marker: ::std::marker::PhantomData<&'mock ()>,
    }

    impl dyn super::client::C {
        pub fn mock<'mock>() -> C<'mock> {
            C {
                f: r#impl::c::f::unimplemented(),
                numbers: r#impl::c::numbers::unimplemented(),
                thing: r#impl::c::thing::unimplemented(),
                _marker: ::std::marker::PhantomData,
            }
        }
    }

    impl<'mock> super::client::C for C<'mock> {
        fn f(
            &self,
        ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<(), crate::errors::c::FError>> {
            let mut closure = self.f.closure.lock().unwrap();
            let closure: &mut dyn ::std::ops::FnMut() -> _ = &mut **closure;
            ::std::boxed::Box::pin(::futures::future::ready(closure()))
        }
        fn numbers(
            &self,
        ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<::futures::stream::BoxStream<'static, ::std::result::Result<crate::types::number, crate::errors::c::NumbersStreamError>>, crate::errors::c::NumbersError>> {
            let mut closure = self.numbers.closure.lock().unwrap();
            let closure: &mut dyn ::std::ops::FnMut() -> _ = &mut **closure;
            ::std::boxed::Box::pin(::futures::future::ready(closure()))
        }
        fn thing(
            &self,
            arg_a: ::std::primitive::i32,
            arg_b: &::std::primitive::str,
            arg_c: &::std::collections::BTreeSet<::std::primitive::i32>,
        ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<::std::string::String, crate::errors::c::ThingError>> {
            let mut closure = self.thing.closure.lock().unwrap();
            let closure: &mut dyn ::std::ops::FnMut(::std::primitive::i32, ::std::string::String, ::std::collections::BTreeSet<::std::primitive::i32>) -> _ = &mut **closure;
            ::std::boxed::Box::pin(::futures::future::ready(closure(arg_a.clone(), arg_b.to_owned(), arg_c.clone())))
        }
    }

    pub mod r#impl {
        pub mod c {

            pub struct f<'mock> {
                pub(crate) closure: ::std::sync::Mutex<::std::boxed::Box<
                    dyn ::std::ops::FnMut() -> ::std::result::Result<
                        (),
                        crate::errors::c::FError,
                    > + ::std::marker::Send + ::std::marker::Sync + 'mock,
                >>,
            }

            #[allow(clippy::redundant_closure)]
            impl<'mock> f<'mock> {
                pub(crate) fn unimplemented() -> Self {
                    Self {
                        closure: ::std::sync::Mutex::new(::std::boxed::Box::new(|| panic!(
                            "{}::{} is not mocked",
                            "C",
                            "f",
                        ))),
                    }
                }

                pub fn ret(&self, value: ()) {
                    self.mock(move || value.clone());
                }

                pub fn mock(&self, mut mock: impl ::std::ops::FnMut() -> () + ::std::marker::Send + ::std::marker::Sync + 'mock) {
                    let mut closure = self.closure.lock().unwrap();
                    *closure = ::std::boxed::Box::new(move || ::std::result::Result::Ok(mock()));
                }

                pub fn mock_result(&self, mut mock: impl ::std::ops::FnMut() -> ::std::result::Result<(), crate::errors::c::FError> + ::std::marker::Send + ::std::marker::Sync + 'mock) {
                    let mut closure = self.closure.lock().unwrap();
                    *closure = ::std::boxed::Box::new(move || mock());
                }

                pub fn throw<E>(&self, exception: E)
                where
                    E: ::std::convert::Into<crate::errors::c::FError>,
                    E: ::std::clone::Clone + ::std::marker::Send + ::std::marker::Sync + 'mock,
                {
                    let mut closure = self.closure.lock().unwrap();
                    *closure = ::std::boxed::Box::new(move || ::std::result::Result::Err(exception.clone().into()));
                }
            }

            pub struct numbers<'mock> {
                pub(crate) closure: ::std::sync::Mutex<::std::boxed::Box<
                    dyn ::std::ops::FnMut() -> ::std::result::Result<
                        ::futures::stream::BoxStream<'static, ::std::result::Result<crate::types::number, crate::errors::c::NumbersStreamError>>,
                        crate::errors::c::NumbersError,
                    > + ::std::marker::Send + ::std::marker::Sync + 'mock,
                >>,
            }

            #[allow(clippy::redundant_closure)]
            impl<'mock> numbers<'mock> {
                pub(crate) fn unimplemented() -> Self {
                    Self {
                        closure: ::std::sync::Mutex::new(::std::boxed::Box::new(|| panic!(
                            "{}::{} is not mocked",
                            "C",
                            "numbers",
                        ))),
                    }
                }

                pub fn ret(&self, _value: ::futures::stream::BoxStream<'static, ::std::result::Result<crate::types::number, crate::errors::c::NumbersStreamError>>) {
                    unimplemented!("Mocking streams is not yet implemented, as value isn't cloneable")
                }

                pub fn mock(&self, mut mock: impl ::std::ops::FnMut() -> ::futures::stream::BoxStream<'static, ::std::result::Result<crate::types::number, crate::errors::c::NumbersStreamError>> + ::std::marker::Send + ::std::marker::Sync + 'mock) {
                    let mut closure = self.closure.lock().unwrap();
                    *closure = ::std::boxed::Box::new(move || ::std::result::Result::Ok(mock()));
                }

                pub fn mock_result(&self, mut mock: impl ::std::ops::FnMut() -> ::std::result::Result<::futures::stream::BoxStream<'static, ::std::result::Result<crate::types::number, crate::errors::c::NumbersStreamError>>, crate::errors::c::NumbersError> + ::std::marker::Send + ::std::marker::Sync + 'mock) {
                    let mut closure = self.closure.lock().unwrap();
                    *closure = ::std::boxed::Box::new(move || mock());
                }

                pub fn throw<E>(&self, exception: E)
                where
                    E: ::std::convert::Into<crate::errors::c::NumbersError>,
                    E: ::std::clone::Clone + ::std::marker::Send + ::std::marker::Sync + 'mock,
                {
                    let mut closure = self.closure.lock().unwrap();
                    *closure = ::std::boxed::Box::new(move || ::std::result::Result::Err(exception.clone().into()));
                }
            }

            pub struct thing<'mock> {
                pub(crate) closure: ::std::sync::Mutex<::std::boxed::Box<
                    dyn ::std::ops::FnMut(::std::primitive::i32, ::std::string::String, ::std::collections::BTreeSet<::std::primitive::i32>) -> ::std::result::Result<
                        ::std::string::String,
                        crate::errors::c::ThingError,
                    > + ::std::marker::Send + ::std::marker::Sync + 'mock,
                >>,
            }

            #[allow(clippy::redundant_closure)]
            impl<'mock> thing<'mock> {
                pub(crate) fn unimplemented() -> Self {
                    Self {
                        closure: ::std::sync::Mutex::new(::std::boxed::Box::new(|_: ::std::primitive::i32, _: ::std::string::String, _: ::std::collections::BTreeSet<::std::primitive::i32>| panic!(
                            "{}::{} is not mocked",
                            "C",
                            "thing",
                        ))),
                    }
                }

                pub fn ret(&self, value: ::std::string::String) {
                    self.mock(move |_: ::std::primitive::i32, _: ::std::string::String, _: ::std::collections::BTreeSet<::std::primitive::i32>| value.clone());
                }

                pub fn mock(&self, mut mock: impl ::std::ops::FnMut(::std::primitive::i32, ::std::string::String, ::std::collections::BTreeSet<::std::primitive::i32>) -> ::std::string::String + ::std::marker::Send + ::std::marker::Sync + 'mock) {
                    let mut closure = self.closure.lock().unwrap();
                    *closure = ::std::boxed::Box::new(move |a, b, c| ::std::result::Result::Ok(mock(a, b, c)));
                }

                pub fn mock_result(&self, mut mock: impl ::std::ops::FnMut(::std::primitive::i32, ::std::string::String, ::std::collections::BTreeSet<::std::primitive::i32>) -> ::std::result::Result<::std::string::String, crate::errors::c::ThingError> + ::std::marker::Send + ::std::marker::Sync + 'mock) {
                    let mut closure = self.closure.lock().unwrap();
                    *closure = ::std::boxed::Box::new(move |a, b, c| mock(a, b, c));
                }

                pub fn throw<E>(&self, exception: E)
                where
                    E: ::std::convert::Into<crate::errors::c::ThingError>,
                    E: ::std::clone::Clone + ::std::marker::Send + ::std::marker::Sync + 'mock,
                {
                    let mut closure = self.closure.lock().unwrap();
                    *closure = ::std::boxed::Box::new(move |_: ::std::primitive::i32, _: ::std::string::String, _: ::std::collections::BTreeSet<::std::primitive::i32>| ::std::result::Result::Err(exception.clone().into()));
                }
            }
        }
    }
}

/// Error return types.
pub mod errors {
    /// Errors for C functions.
    pub mod c {

        pub trait AsBang {
            fn as_bang(&self) -> Option<&crate::types::Bang>;
        }

        impl AsBang for ::anyhow::Error {
            fn as_bang(&self) -> Option<&crate::types::Bang> {
                for cause in self.chain() {
                    if let Some(ThingError::bang(e)) = cause.downcast_ref::<ThingError>() {
                        return Some(e);
                    }
                }
                None
            }
        }

        pub type FError = ::fbthrift::NonthrowingFunctionError;

        impl ::std::convert::From<crate::services::c::FExn> for
            ::std::result::Result<(), FError>
        {
            fn from(e: crate::services::c::FExn) -> Self {
                match e {
                    crate::services::c::FExn::Success(res) => {
                        ::std::result::Result::Ok(res)
                    }
                    crate::services::c::FExn::ApplicationException(aexn) =>
                        ::std::result::Result::Err(FError::ApplicationException(aexn)),
                }
            }
        }

        pub type NumbersError = ::fbthrift::NonthrowingFunctionError;

        impl ::std::convert::From<crate::services::c::NumbersExn> for
            ::std::result::Result<::futures::stream::BoxStream<'static, ::std::result::Result<crate::types::number, crate::errors::c::NumbersStreamError>>, NumbersError>
        {
            fn from(e: crate::services::c::NumbersExn) -> Self {
                match e {
                    crate::services::c::NumbersExn::Success(res) => {
                        use ::futures::stream::StreamExt;
                        let stream = res;
                        ::std::result::Result::Ok(stream.map(|res| match res {
                            ::std::result::Result::Ok(item) => ::std::result::Result::Ok(item),
                            ::std::result::Result::Err(exn) => exn.into(),
                        }).boxed())
                    }
                    crate::services::c::NumbersExn::ApplicationException(aexn) =>
                        ::std::result::Result::Err(NumbersError::ApplicationException(aexn)),
                }
            }
        }

        impl ::std::convert::From<crate::services::c::NumbersResponseExn> for
            ::std::result::Result<(), NumbersError>
        {
            fn from(e: crate::services::c::NumbersResponseExn) -> Self {
                match e {
                    crate::services::c::NumbersResponseExn::Success(res) =>
                        ::std::result::Result::Ok(res),
                    crate::services::c::NumbersResponseExn::ApplicationException(aexn) =>
                        ::std::result::Result::Err(NumbersError::ApplicationException(aexn)),
                }
            }
        }

        pub type NumbersStreamError = ::fbthrift::NonthrowingFunctionError;

        impl ::std::convert::From<crate::services::c::NumbersStreamExn> for
            ::std::result::Result<crate::types::number, NumbersStreamError>
        {
            fn from(e: crate::services::c::NumbersStreamExn) -> Self {
                match e {
                    crate::services::c::NumbersStreamExn::Success(res) =>
                        ::std::result::Result::Ok(res),
                    crate::services::c::NumbersStreamExn::ApplicationException(aexn) =>
                        ::std::result::Result::Err(NumbersStreamError::ApplicationException(aexn)),
                }
            }
        }

        /// Errors for thing (client side).
        #[derive(Debug)]
        pub enum ThingError {
            bang(crate::types::Bang),
            ApplicationException(::fbthrift::types::ApplicationException),
            ThriftError(::anyhow::Error),
        }

        /// Human-readable string representation of the Thrift client error.
        ///
        /// By default, this will not print the full cause chain. If you would like to print the underlying error
        /// cause, either use `format!("{:?}", anyhow::Error::from(client_err))` or print this using the
        /// alternate formatter `{:#}` instead of just `{}`.
        impl ::std::fmt::Display for ThingError {
            fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::result::Result<(), ::std::fmt::Error> {
                match self {
                    Self::bang(inner) => {
                        if f.alternate() {
                            write!(f, "C::thing failed with variant `bang`: {:#}", inner)?;
                        } else {
                            write!(f, "C::thing failed with bang(Bang)")?;
                        }
                    }
                    Self::ApplicationException(inner) => {
                        write!(f, "C::thing failed with ApplicationException")?;

                        if f.alternate() {
                          write!(f, ": {:#}", inner)?;
                        }
                    }
                    Self::ThriftError(inner) => {
                        write!(f, "C::thing failed with ThriftError")?;

                        if f.alternate() {
                          write!(f, ": {:#}", inner)?;
                        }
                    }
                }

                Ok(())
            }
        }

        impl ::std::error::Error for ThingError {
            fn source(&self) -> ::std::option::Option<&(dyn ::std::error::Error + 'static)> {
                match self {
                    Self::bang(ref inner) => {
                        Some(inner)
                    }
                    Self::ApplicationException(ref inner) => {
                        Some(inner)
                    }
                    Self::ThriftError(ref inner) => {
                        Some(inner.as_ref())
                    }
                }
            }
        }

        impl ::std::convert::From<crate::types::Bang> for ThingError {
            fn from(e: crate::types::Bang) -> Self {
                Self::bang(e)
            }
        }

        impl AsBang for ThingError {
            fn as_bang(&self) -> Option<&crate::types::Bang> {
                match self {
                    Self::bang(inner) => Some(inner),
                    _ => None,
                }
            }
        }

        impl ::std::convert::From<::anyhow::Error> for ThingError {
            fn from(err: ::anyhow::Error) -> Self {
                Self::ThriftError(err)
            }
        }

        impl ::std::convert::From<::fbthrift::ApplicationException> for ThingError {
            fn from(ae: ::fbthrift::ApplicationException) -> Self {
                Self::ApplicationException(ae)
            }
        }
        impl ::std::convert::From<crate::services::c::ThingExn> for
            ::std::result::Result<::std::string::String, ThingError>
        {
            fn from(e: crate::services::c::ThingExn) -> Self {
                match e {
                    crate::services::c::ThingExn::Success(res) => {
                        ::std::result::Result::Ok(res)
                    }
                    crate::services::c::ThingExn::ApplicationException(aexn) =>
                        ::std::result::Result::Err(ThingError::ApplicationException(aexn)),
                    crate::services::c::ThingExn::bang(exn) =>
                        ::std::result::Result::Err(ThingError::bang(exn)),
                }
            }
        }

    }

}