Struct unimock::build::DefineResponse
source · Expand description
A matched call pattern, ready for defining a single response.
Implementations
sourceimpl<'p, F: MockFn, O: Ordering> DefineResponse<'p, F, O>where
<F::Response as Respond>::Type: Send + Sync,
impl<'p, F: MockFn, O: Ordering> DefineResponse<'p, F, O>where
<F::Response as Respond>::Type: Send + Sync,
sourcepub fn returns<T>(self, value: T) -> QuantifyReturnValue<'p, F, T, O>where
T: IntoResponseOnce<F::Response>,
pub fn returns<T>(self, value: T) -> QuantifyReturnValue<'p, F, T, O>where
T: IntoResponseOnce<F::Response>,
Specify the output of the call pattern by providing a value. The output type cannot contain non-static references. It must also be Send and Sync because unimock needs to store it.
Unless explicitly configured on the returned QuantifyReturnValue, the return value specified here can be returned only once, because this method does not require a Clone bound. To be able to return this value multiple times, quantify it explicitly.
sourceimpl<'p, F, O> DefineResponse<'p, F, O>where
F: MockFn + 'static,
O: Ordering,
impl<'p, F, O> DefineResponse<'p, F, O>where
F: MockFn + 'static,
O: Ordering,
sourcepub fn returns_default(self) -> Quantify<'p, F, O>where
<F::Response as Respond>::Type: Default,
pub fn returns_default(self) -> Quantify<'p, F, O>where
<F::Response as Respond>::Type: Default,
Specify the response of the call pattern by calling Default::default()
.
sourcepub fn answers<C, R>(self, func: C) -> Quantify<'p, F, O>where
C: for<'i> Fn(F::Inputs<'i>) -> R + Send + Sync + 'static,
R: IntoResponseOnce<F::Response>,
pub fn answers<C, R>(self, func: C) -> Quantify<'p, F, O>where
C: for<'i> Fn(F::Inputs<'i>) -> R + Send + Sync + 'static,
R: IntoResponseOnce<F::Response>,
Specify the response of the call pattern by invoking the given closure that can then compute it based on input parameters.
sourcepub fn answers_leaked_ref<C, R, T>(self, func: C) -> Quantify<'p, F, O>where
F: MockFn<Response = StaticRef<T>>,
C: for<'i> Fn(F::Inputs<'i>) -> R + Send + Sync + 'static,
R: Borrow<T> + 'static,
T: 'static,
pub fn answers_leaked_ref<C, R, T>(self, func: C) -> Quantify<'p, F, O>where
F: MockFn<Response = StaticRef<T>>,
C: for<'i> Fn(F::Inputs<'i>) -> R + Send + Sync + 'static,
R: Borrow<T> + 'static,
T: 'static,
Specify the response of the call pattern to be a static reference to leaked memory.
The value may be based on the value of input parameters.
This version will produce a new memory leak for every invocation of the answer function.
This method should only be used when computing a reference based on input parameters is necessary, which should not be a common use case.
sourcepub fn panics(self, message: impl Into<String>) -> Quantify<'p, F, O>
pub fn panics(self, message: impl Into<String>) -> Quantify<'p, F, O>
Prevent this call pattern from succeeding by explicitly panicking with a custom message.
sourcepub fn unmocked(self) -> Quantify<'p, F, O>
pub fn unmocked(self) -> Quantify<'p, F, O>
Instruct this call pattern to invoke its corresponding unmocked
function.
For this to work, the mocked trait must be configured with an unmock_with=[..]
parameter.
If unimock doesn’t find a way to unmock the function, this will panic when the function is called.