Adding support for .returns should be possible, but some technically backwards-incompatible changes are needed.
Accessing the output value of a return responder is done using a method called get_output(&self). To add mutation support it needs another method like get_output_mut(&mut self) and the eval function also needs its own mutable version (eval_mut(&mut Unimock, ..)) to be able to call the new method.
edit: also consider supporting fragile returns, but not 100% sure. Fragile values are more likely to cause problems when used as returns compared to created in answer fns. For example, a cloned Unimock used from another thread won't work.
https://github.com/audunhalland/unimock/pull/49 added support for mutable references from
AnswerFn
.Adding support for
.returns
should be possible, but some technically backwards-incompatible changes are needed.Accessing the output value of a return responder is done using a method called
get_output(&self)
. To add mutation support it needs another method likeget_output_mut(&mut self)
and theeval
function also needs its own mutable version (eval_mut(&mut Unimock, ..)
) to be able to call the new method.edit: also consider supporting
fragile
returns, but not 100% sure. Fragile values are more likely to cause problems when used as returns compared to created in answer fns. For example, a cloned Unimock used from another thread won't work.