use std::any::Any;
use std::io::Error;
#[doc(hidden)]
pub mod http;
mod provider;
pub use self::provider::ResponseProvider;
pub trait MockResponse: Send {
fn matches(&self, &Box<MockRequest>) -> bool;
fn respond(&mut self, Box<MockRequest>) -> MockRequestResponse;
fn validate(&mut self, response_index: usize, request_index: usize) -> Vec<String>;
fn validate_header(&self, error_count: usize) -> String;
}
pub trait MockRequest: Send + Any {
fn validate(&mut self) -> Option<String>;
#[cfg_attr(feature = "clippy", allow(needless_lifetimes))]
fn downcast_ref<'a>(
request: &'a Box<MockRequest>
) -> Option<&'a Self> where Self: Any + Send + Sized + 'static {
request.as_any().downcast_ref::<Self>()
}
#[cfg_attr(feature = "clippy", allow(needless_lifetimes))]
fn downcast_mut<'a>(
request: &'a mut Box<MockRequest>
) -> Option<&'a mut Self> where Self: Any + Send + Sized + 'static {
request.as_any_mut().downcast_mut::<Self>()
}
fn as_any(&self) -> &Any;
fn as_any_mut(&mut self) -> &mut Any;
}
pub trait MockProvider: Send {
fn setup(&mut self);
fn teardown(&mut self);
}
pub type MockRequestResponse = Result<Vec<u8>, Error>;
pub struct MockResponseProvider;
impl MockResponseProvider {
pub fn response_from_request(
request: Box<MockRequest>
) -> Result<MockRequestResponse, Error> where Self: Sized {
ResponseProvider::request(request)
}
}