pub struct RuleBuilder<I, O, E> { /* private fields */ }
Implementations§
source§impl<I, O, E> RuleBuilder<I, O, E>
impl<I, O, E> RuleBuilder<I, O, E>
sourcepub fn new<F, R>(
_input_hint: impl Fn() -> I,
_output_hint: impl Fn() -> F,
) -> Self
pub fn new<F, R>( _input_hint: impl Fn() -> I, _output_hint: impl Fn() -> F, ) -> Self
Creates a new RuleBuilder
. This is normally constructed with the mock!
macro
sourcepub fn match_requests(
self,
filter: impl Fn(&I) -> bool + Send + Sync + 'static,
) -> Self
pub fn match_requests( self, filter: impl Fn(&I) -> bool + Send + Sync + 'static, ) -> Self
Add an additional filter to constrain which inputs match this rule.
For examples, see the examples directory of this repository.
sourcepub fn then_http_response(
self,
response: impl Fn() -> HttpResponse + Send + Sync + 'static,
) -> Rule
pub fn then_http_response( self, response: impl Fn() -> HttpResponse + Send + Sync + 'static, ) -> Rule
If the rule matches, then return a specific HTTP response.
This is the recommended way of testing error behavior.
sourcepub fn then_output(self, output: impl Fn() -> O + Send + Sync + 'static) -> Rule
pub fn then_output(self, output: impl Fn() -> O + Send + Sync + 'static) -> Rule
If a rule matches, then return a specific output
sourcepub fn then_error(self, output: impl Fn() -> E + Send + Sync + 'static) -> Rule
pub fn then_error(self, output: impl Fn() -> E + Send + Sync + 'static) -> Rule
If a rule matches, then return a specific error
Although this basically works, using then_http_response
is strongly recommended to
create a higher fidelity mock. Error handling is quite complex in practice and returning errors
directly often will not perfectly capture the way the error is actually returned to the SDK.
Auto Trait Implementations§
impl<I, O, E> Freeze for RuleBuilder<I, O, E>
impl<I, O, E> !RefUnwindSafe for RuleBuilder<I, O, E>
impl<I, O, E> Send for RuleBuilder<I, O, E>
impl<I, O, E> Sync for RuleBuilder<I, O, E>
impl<I, O, E> Unpin for RuleBuilder<I, O, E>
impl<I, O, E> !UnwindSafe for RuleBuilder<I, O, E>
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
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreCreates a shared type from an unshared type.