Struct zebra_test::mock_service::ResponseSender
source · pub struct ResponseSender<Request, Response, Error> { /* private fields */ }
Expand description
A helper type for responding to incoming requests.
An instance of this type is created for each request received by the MockService
. It
contains the received request and a [oneshot::Sender
] that can be used to respond to the
request.
If a response is not sent, the channel is closed and a [BoxError
] is returned by the service
to the caller that sent the request.
Implementations§
source§impl<Request, Response, Error> ResponseSender<Request, Response, Error>
impl<Request, Response, Error> ResponseSender<Request, Response, Error>
sourcepub fn respond(self, response: impl ResponseResult<Response, Error>)
pub fn respond(self, response: impl ResponseResult<Response, Error>)
Respond to the request using a fixed response value.
The response
can be of the Response
type or a Result
. This allows sending an error
representing an error while processing the request.
This method takes ownership of the ResponseSender
so that only one response can be
sent.
Panics
If one of the respond*
methods isn’t called, the MockService
might panic with a
timeout error.
Example
// Mock a service with a `String` as the service `Error` type.
let mut mock_service: MockService<_, _, _, String> =
MockService::build().for_unit_tests();
mock_service
.expect_request(Request)
.await
.respond("Received Request".to_owned());
mock_service
.expect_request(Request)
.await
.respond(Err("Duplicate request"));
sourcepub fn respond_with<F, R>(self, response_fn: F)where
F: FnOnce(&Request) -> R,
R: ResponseResult<Response, Error>,
pub fn respond_with<F, R>(self, response_fn: F)where F: FnOnce(&Request) -> R, R: ResponseResult<Response, Error>,
Respond to the request by calculating a value from the request.
The response can be of the Response
type or a Result
. This allows sending an error
representing an error while processing the request.
This method takes ownership of the ResponseSender
so that only one response can be
sent.
Panics
If one of the respond*
methods isn’t called, the MockService
might panic with a
timeout error.
Example
// Mock a service with a `String` as the service `Error` type.
let mut mock_service: MockService<_, _, _, String> =
MockService::build().for_unit_tests();
mock_service
.expect_request(Request)
.await
.respond_with(|req| format!("Received: {req:?}"));
mock_service
.expect_request(Request)
.await
.respond_with(|req| Err(format!("Duplicate request: {req:?}")));
sourcepub fn respond_error(self, error: Error)
pub fn respond_error(self, error: Error)
Respond to the request using a fixed error value.
The error
must be the Error
type. This helps avoid type resolution issues in the
compiler.
This method takes ownership of the ResponseSender
so that only one response can be
sent.
Panics
If one of the respond*
methods isn’t called, the MockService
might panic with a
timeout error.
Example
// Mock a service with a `String` as the service `Error` type.
let mut mock_service: MockService<Request, Response, _, String> =
MockService::build().for_unit_tests();
mock_service
.expect_request(Request)
.await
.respond_error("Duplicate request".to_string());
sourcepub fn respond_with_error<F>(self, response_fn: F)where
F: FnOnce(&Request) -> Error,
pub fn respond_with_error<F>(self, response_fn: F)where F: FnOnce(&Request) -> Error,
Respond to the request by calculating an error from the request.
The error
must be the Error
type. This helps avoid type resolution issues in the
compiler.
This method takes ownership of the ResponseSender
so that only one response can be
sent.
Panics
If one of the respond*
methods isn’t called, the MockService
might panic with a
timeout error.
Example
// Mock a service with a `String` as the service `Error` type.
let mut mock_service: MockService<Request, Response, _, String> =
MockService::build().for_unit_tests();
mock_service
.expect_request(Request)
.await
.respond_with_error(|req| format!("Duplicate request: {req:?}"));
Auto Trait Implementations§
impl<Request, Response, Error> !RefUnwindSafe for ResponseSender<Request, Response, Error>
impl<Request, Response, Error> Send for ResponseSender<Request, Response, Error>where Error: Send, Request: Send, Response: Send,
impl<Request, Response, Error> Sync for ResponseSender<Request, Response, Error>where Error: Send, Request: Sync, Response: Send,
impl<Request, Response, Error> Unpin for ResponseSender<Request, Response, Error>where Request: Unpin,
impl<Request, Response, Error> !UnwindSafe for ResponseSender<Request, Response, Error>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where C: Color,
§fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
§fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
§fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
§fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
§fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
§fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
§fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
§fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
§fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
§fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
§fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
§fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
§fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
§fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
§fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
§fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
§fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
§fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
§fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
§fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
§fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
§fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
§fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
§fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
§fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
§fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where Color: DynColor,
OwoColorize::fg
or
a color-specific method, such as OwoColorize::green
, Read more§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where Color: DynColor,
OwoColorize::bg
or
a color-specific method, such as OwoColorize::on_yellow
, Read more§fn fg_rgb<const R: u8, const G: u8, const B: u8>(
&self
) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>
fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>
§fn bg_rgb<const R: u8, const G: u8, const B: u8>(
&self
) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>
fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>
§fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>
fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>
§fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>
fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>
source§impl<Response, Error> ResponseResult<Response, Error> for Response
impl<Response, Error> ResponseResult<Response, Error> for Response
source§fn into_result(self) -> Result<Response, Error>
fn into_result(self) -> Result<Response, Error>
Result
that can be sent as a response.