// @generated by Thrift for thrift/compiler/test/fixtures/rust-annotations/src/module.thrift // This file is probably not the place you want to edit! //! Mock definitions for `module`. //! //! 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 + Send + Sync + 'mock, //! ); //! //! // return one of the function's declared exceptions //! pub fn throw(&self, exception: E) //! where //! E: Clone + Into + Send + Sync + 'mock; //! } //! //! impl From for MyFunctionExn {...} //! impl From 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(::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, //! ) -> impl Future {...} //! # }; //! ``` pub struct Service1<'mock> { pub r: r#impl::service1::r<'mock>, _marker: ::std::marker::PhantomData<&'mock ()>, } impl dyn super::client::Service1 { pub fn mock<'mock>() -> Service1<'mock> { Service1 { r: r#impl::service1::r::unimplemented(), _marker: ::std::marker::PhantomData, } } } impl<'mock> super::client::Service1 for Service1<'mock> { fn r( &self, ) -> ::futures::future::BoxFuture<'static, ::std::result::Result> { let mut closure = self.r.closure.lock().unwrap(); let closure: &mut dyn ::std::ops::FnMut() -> _ = &mut **closure; ::std::boxed::Box::pin(::futures::future::ready(closure())) } } pub struct S2<'mock> { pub s: r#impl::s2::s<'mock>, _marker: ::std::marker::PhantomData<&'mock ()>, } impl dyn super::client::S2 { pub fn mock<'mock>() -> S2<'mock> { S2 { s: r#impl::s2::s::unimplemented(), _marker: ::std::marker::PhantomData, } } } impl<'mock> super::client::S2 for S2<'mock> { fn s( &self, ) -> ::futures::future::BoxFuture<'static, ::std::result::Result> { let mut closure = self.s.closure.lock().unwrap(); let closure: &mut dyn ::std::ops::FnMut() -> _ = &mut **closure; ::std::boxed::Box::pin(::futures::future::ready(closure())) } } pub struct AllMethods<'mock> { pub foo: r#impl::all_methods::foo<'mock>, pub bar: r#impl::all_methods::bar<'mock>, _marker: ::std::marker::PhantomData<&'mock ()>, } impl dyn super::client::AllMethods { pub fn mock<'mock>() -> AllMethods<'mock> { AllMethods { foo: r#impl::all_methods::foo::unimplemented(), bar: r#impl::all_methods::bar::unimplemented(), _marker: ::std::marker::PhantomData, } } } impl<'mock> super::client::AllMethods for AllMethods<'mock> { fn foo( &self, ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<(), crate::errors::all_methods::FooError>> { let mut closure = self.foo.closure.lock().unwrap(); let closure: &mut dyn ::std::ops::FnMut() -> _ = &mut **closure; ::std::boxed::Box::pin(::futures::future::ready(closure())) } fn bar( &self, ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<::std::string::String, crate::errors::all_methods::BarError>> { let mut closure = self.bar.closure.lock().unwrap(); let closure: &mut dyn ::std::ops::FnMut() -> _ = &mut **closure; ::std::boxed::Box::pin(::futures::future::ready(closure())) } } pub struct OneMethod<'mock> { pub foo: r#impl::one_method::foo<'mock>, pub bar: r#impl::one_method::bar<'mock>, _marker: ::std::marker::PhantomData<&'mock ()>, } impl dyn super::client::OneMethod { pub fn mock<'mock>() -> OneMethod<'mock> { OneMethod { foo: r#impl::one_method::foo::unimplemented(), bar: r#impl::one_method::bar::unimplemented(), _marker: ::std::marker::PhantomData, } } } impl<'mock> super::client::OneMethod for OneMethod<'mock> { fn foo( &self, ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<(), crate::errors::one_method::FooError>> { let mut closure = self.foo.closure.lock().unwrap(); let closure: &mut dyn ::std::ops::FnMut() -> _ = &mut **closure; ::std::boxed::Box::pin(::futures::future::ready(closure())) } fn bar( &self, ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<::std::string::String, crate::errors::one_method::BarError>> { let mut closure = self.bar.closure.lock().unwrap(); let closure: &mut dyn ::std::ops::FnMut() -> _ = &mut **closure; ::std::boxed::Box::pin(::futures::future::ready(closure())) } } pub struct OneMethodOptOut<'mock> { pub foo: r#impl::one_method_opt_out::foo<'mock>, pub bar: r#impl::one_method_opt_out::bar<'mock>, _marker: ::std::marker::PhantomData<&'mock ()>, } impl dyn super::client::OneMethodOptOut { pub fn mock<'mock>() -> OneMethodOptOut<'mock> { OneMethodOptOut { foo: r#impl::one_method_opt_out::foo::unimplemented(), bar: r#impl::one_method_opt_out::bar::unimplemented(), _marker: ::std::marker::PhantomData, } } } impl<'mock> super::client::OneMethodOptOut for OneMethodOptOut<'mock> { fn foo( &self, ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<(), crate::errors::one_method_opt_out::FooError>> { let mut closure = self.foo.closure.lock().unwrap(); let closure: &mut dyn ::std::ops::FnMut() -> _ = &mut **closure; ::std::boxed::Box::pin(::futures::future::ready(closure())) } fn bar( &self, ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<::std::string::String, crate::errors::one_method_opt_out::BarError>> { let mut closure = self.bar.closure.lock().unwrap(); let closure: &mut dyn ::std::ops::FnMut() -> _ = &mut **closure; ::std::boxed::Box::pin(::futures::future::ready(closure())) } } pub mod r#impl { pub mod service1 { pub struct r<'mock> { pub(crate) closure: ::std::sync::Mutex<::std::boxed::Box< dyn ::std::ops::FnMut() -> ::std::result::Result< crate::types::T6, crate::errors::service1::RError, > + ::std::marker::Send + ::std::marker::Sync + 'mock, >>, } #[allow(clippy::redundant_closure)] impl<'mock> r<'mock> { pub(crate) fn unimplemented() -> Self { Self { closure: ::std::sync::Mutex::new(::std::boxed::Box::new(|| panic!( "{}::{} is not mocked", "Service1", "r", ))), } } pub fn ret(&self, value: crate::types::T6) { self.mock(move || value.clone()); } pub fn mock(&self, mut mock: impl ::std::ops::FnMut() -> crate::types::T6 + ::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 + ::std::marker::Send + ::std::marker::Sync + 'mock) { let mut closure = self.closure.lock().unwrap(); *closure = ::std::boxed::Box::new(move || mock()); } pub fn throw(&self, exception: E) where E: ::std::convert::Into, 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 mod s2 { pub struct s<'mock> { pub(crate) closure: ::std::sync::Mutex<::std::boxed::Box< dyn ::std::ops::FnMut() -> ::std::result::Result< crate::types::T6, crate::errors::s2::RError, > + ::std::marker::Send + ::std::marker::Sync + 'mock, >>, } #[allow(clippy::redundant_closure)] impl<'mock> s<'mock> { pub(crate) fn unimplemented() -> Self { Self { closure: ::std::sync::Mutex::new(::std::boxed::Box::new(|| panic!( "{}::{} is not mocked", "S2", "r", ))), } } pub fn ret(&self, value: crate::types::T6) { self.mock(move || value.clone()); } pub fn mock(&self, mut mock: impl ::std::ops::FnMut() -> crate::types::T6 + ::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 + ::std::marker::Send + ::std::marker::Sync + 'mock) { let mut closure = self.closure.lock().unwrap(); *closure = ::std::boxed::Box::new(move || mock()); } pub fn throw(&self, exception: E) where E: ::std::convert::Into, 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 mod all_methods { pub struct foo<'mock> { pub(crate) closure: ::std::sync::Mutex<::std::boxed::Box< dyn ::std::ops::FnMut() -> ::std::result::Result< (), crate::errors::all_methods::FooError, > + ::std::marker::Send + ::std::marker::Sync + 'mock, >>, } #[allow(clippy::redundant_closure)] impl<'mock> foo<'mock> { pub(crate) fn unimplemented() -> Self { Self { closure: ::std::sync::Mutex::new(::std::boxed::Box::new(|| panic!( "{}::{} is not mocked", "AllMethods", "foo", ))), } } 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::all_methods::FooError> + ::std::marker::Send + ::std::marker::Sync + 'mock) { let mut closure = self.closure.lock().unwrap(); *closure = ::std::boxed::Box::new(move || mock()); } pub fn throw(&self, exception: E) where E: ::std::convert::Into, 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 bar<'mock> { pub(crate) closure: ::std::sync::Mutex<::std::boxed::Box< dyn ::std::ops::FnMut() -> ::std::result::Result< ::std::string::String, crate::errors::all_methods::BarError, > + ::std::marker::Send + ::std::marker::Sync + 'mock, >>, } #[allow(clippy::redundant_closure)] impl<'mock> bar<'mock> { pub(crate) fn unimplemented() -> Self { Self { closure: ::std::sync::Mutex::new(::std::boxed::Box::new(|| panic!( "{}::{} is not mocked", "AllMethods", "bar", ))), } } pub fn ret(&self, value: ::std::string::String) { self.mock(move || value.clone()); } pub fn mock(&self, mut mock: impl ::std::ops::FnMut() -> ::std::string::String + ::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<::std::string::String, crate::errors::all_methods::BarError> + ::std::marker::Send + ::std::marker::Sync + 'mock) { let mut closure = self.closure.lock().unwrap(); *closure = ::std::boxed::Box::new(move || mock()); } pub fn throw(&self, exception: E) where E: ::std::convert::Into, 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 mod one_method { pub struct foo<'mock> { pub(crate) closure: ::std::sync::Mutex<::std::boxed::Box< dyn ::std::ops::FnMut() -> ::std::result::Result< (), crate::errors::one_method::FooError, > + ::std::marker::Send + ::std::marker::Sync + 'mock, >>, } #[allow(clippy::redundant_closure)] impl<'mock> foo<'mock> { pub(crate) fn unimplemented() -> Self { Self { closure: ::std::sync::Mutex::new(::std::boxed::Box::new(|| panic!( "{}::{} is not mocked", "OneMethod", "foo", ))), } } 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::one_method::FooError> + ::std::marker::Send + ::std::marker::Sync + 'mock) { let mut closure = self.closure.lock().unwrap(); *closure = ::std::boxed::Box::new(move || mock()); } pub fn throw(&self, exception: E) where E: ::std::convert::Into, 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 bar<'mock> { pub(crate) closure: ::std::sync::Mutex<::std::boxed::Box< dyn ::std::ops::FnMut() -> ::std::result::Result< ::std::string::String, crate::errors::one_method::BarError, > + ::std::marker::Send + ::std::marker::Sync + 'mock, >>, } #[allow(clippy::redundant_closure)] impl<'mock> bar<'mock> { pub(crate) fn unimplemented() -> Self { Self { closure: ::std::sync::Mutex::new(::std::boxed::Box::new(|| panic!( "{}::{} is not mocked", "OneMethod", "bar", ))), } } pub fn ret(&self, value: ::std::string::String) { self.mock(move || value.clone()); } pub fn mock(&self, mut mock: impl ::std::ops::FnMut() -> ::std::string::String + ::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<::std::string::String, crate::errors::one_method::BarError> + ::std::marker::Send + ::std::marker::Sync + 'mock) { let mut closure = self.closure.lock().unwrap(); *closure = ::std::boxed::Box::new(move || mock()); } pub fn throw(&self, exception: E) where E: ::std::convert::Into, 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 mod one_method_opt_out { pub struct foo<'mock> { pub(crate) closure: ::std::sync::Mutex<::std::boxed::Box< dyn ::std::ops::FnMut() -> ::std::result::Result< (), crate::errors::one_method_opt_out::FooError, > + ::std::marker::Send + ::std::marker::Sync + 'mock, >>, } #[allow(clippy::redundant_closure)] impl<'mock> foo<'mock> { pub(crate) fn unimplemented() -> Self { Self { closure: ::std::sync::Mutex::new(::std::boxed::Box::new(|| panic!( "{}::{} is not mocked", "OneMethodOptOut", "foo", ))), } } 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::one_method_opt_out::FooError> + ::std::marker::Send + ::std::marker::Sync + 'mock) { let mut closure = self.closure.lock().unwrap(); *closure = ::std::boxed::Box::new(move || mock()); } pub fn throw(&self, exception: E) where E: ::std::convert::Into, 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 bar<'mock> { pub(crate) closure: ::std::sync::Mutex<::std::boxed::Box< dyn ::std::ops::FnMut() -> ::std::result::Result< ::std::string::String, crate::errors::one_method_opt_out::BarError, > + ::std::marker::Send + ::std::marker::Sync + 'mock, >>, } #[allow(clippy::redundant_closure)] impl<'mock> bar<'mock> { pub(crate) fn unimplemented() -> Self { Self { closure: ::std::sync::Mutex::new(::std::boxed::Box::new(|| panic!( "{}::{} is not mocked", "OneMethodOptOut", "bar", ))), } } pub fn ret(&self, value: ::std::string::String) { self.mock(move || value.clone()); } pub fn mock(&self, mut mock: impl ::std::ops::FnMut() -> ::std::string::String + ::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<::std::string::String, crate::errors::one_method_opt_out::BarError> + ::std::marker::Send + ::std::marker::Sync + 'mock) { let mut closure = self.closure.lock().unwrap(); *closure = ::std::boxed::Box::new(move || mock()); } pub fn throw(&self, exception: E) where E: ::std::convert::Into, 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())); } } } }