// @generated by Thrift for thrift/compiler/test/fixtures/inheritance/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 MyRoot<'mock> { pub do_root: r#impl::my_root::do_root<'mock>, _marker: ::std::marker::PhantomData<&'mock ()>, } impl dyn super::client::MyRoot { pub fn mock<'mock>() -> MyRoot<'mock> { MyRoot { do_root: r#impl::my_root::do_root::unimplemented(), _marker: ::std::marker::PhantomData, } } } impl<'mock> super::client::MyRoot for MyRoot<'mock> { fn do_root( &self, ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<(), crate::errors::my_root::DoRootError>> { let mut closure = self.do_root.closure.lock().unwrap(); let closure: &mut dyn ::std::ops::FnMut() -> _ = &mut **closure; ::std::boxed::Box::pin(::futures::future::ready(closure())) } } pub struct MyNode<'mock> { pub parent: crate::mock::MyRoot<'mock>, pub do_mid: r#impl::my_node::do_mid<'mock>, _marker: ::std::marker::PhantomData<&'mock ()>, } impl dyn super::client::MyNode { pub fn mock<'mock>() -> MyNode<'mock> { MyNode { parent: ::mock(), do_mid: r#impl::my_node::do_mid::unimplemented(), _marker: ::std::marker::PhantomData, } } } impl<'mock> super::client::MyNode for MyNode<'mock> { fn do_mid( &self, ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<(), crate::errors::my_node::DoMidError>> { let mut closure = self.do_mid.closure.lock().unwrap(); let closure: &mut dyn ::std::ops::FnMut() -> _ = &mut **closure; ::std::boxed::Box::pin(::futures::future::ready(closure())) } } #[::async_trait::async_trait] #[allow(deprecated)] impl<'mock> ::std::convert::AsRef for MyNode<'mock> { fn as_ref(&self) -> &(dyn crate::MyRoot + 'mock) { &self.parent } } pub struct MyLeaf<'mock> { pub parent: crate::mock::MyNode<'mock>, pub do_leaf: r#impl::my_leaf::do_leaf<'mock>, _marker: ::std::marker::PhantomData<&'mock ()>, } impl dyn super::client::MyLeaf { pub fn mock<'mock>() -> MyLeaf<'mock> { MyLeaf { parent: ::mock(), do_leaf: r#impl::my_leaf::do_leaf::unimplemented(), _marker: ::std::marker::PhantomData, } } } impl<'mock> super::client::MyLeaf for MyLeaf<'mock> { fn do_leaf( &self, ) -> ::futures::future::BoxFuture<'static, ::std::result::Result<(), crate::errors::my_leaf::DoLeafError>> { let mut closure = self.do_leaf.closure.lock().unwrap(); let closure: &mut dyn ::std::ops::FnMut() -> _ = &mut **closure; ::std::boxed::Box::pin(::futures::future::ready(closure())) } } #[::async_trait::async_trait] #[allow(deprecated)] impl<'mock> ::std::convert::AsRef for MyLeaf<'mock> { fn as_ref(&self) -> &(dyn crate::MyNode + 'mock) { &self.parent } } #[::async_trait::async_trait] #[allow(deprecated)] impl<'mock> ::std::convert::AsRef for MyLeaf<'mock> { fn as_ref(&self) -> &(dyn crate::MyRoot + 'mock) { &self.parent } } pub mod r#impl { pub mod my_root { pub struct do_root<'mock> { pub(crate) closure: ::std::sync::Mutex<::std::boxed::Box< dyn ::std::ops::FnMut() -> ::std::result::Result< (), crate::errors::my_root::DoRootError, > + ::std::marker::Send + ::std::marker::Sync + 'mock, >>, } #[allow(clippy::redundant_closure)] impl<'mock> do_root<'mock> { pub(crate) fn unimplemented() -> Self { Self { closure: ::std::sync::Mutex::new(::std::boxed::Box::new(|| panic!( "{}::{} is not mocked", "MyRoot", "do_root", ))), } } 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::my_root::DoRootError> + ::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 my_node { pub struct do_mid<'mock> { pub(crate) closure: ::std::sync::Mutex<::std::boxed::Box< dyn ::std::ops::FnMut() -> ::std::result::Result< (), crate::errors::my_node::DoMidError, > + ::std::marker::Send + ::std::marker::Sync + 'mock, >>, } #[allow(clippy::redundant_closure)] impl<'mock> do_mid<'mock> { pub(crate) fn unimplemented() -> Self { Self { closure: ::std::sync::Mutex::new(::std::boxed::Box::new(|| panic!( "{}::{} is not mocked", "MyNode", "do_mid", ))), } } 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::my_node::DoMidError> + ::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 my_leaf { pub struct do_leaf<'mock> { pub(crate) closure: ::std::sync::Mutex<::std::boxed::Box< dyn ::std::ops::FnMut() -> ::std::result::Result< (), crate::errors::my_leaf::DoLeafError, > + ::std::marker::Send + ::std::marker::Sync + 'mock, >>, } #[allow(clippy::redundant_closure)] impl<'mock> do_leaf<'mock> { pub(crate) fn unimplemented() -> Self { Self { closure: ::std::sync::Mutex::new(::std::boxed::Box::new(|| panic!( "{}::{} is not mocked", "MyLeaf", "do_leaf", ))), } } 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::my_leaf::DoLeafError> + ::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())); } } } }