audunhalland / unimock

A versatile and developer-friendly trait mocking library
MIT License
71 stars 3 forks source link

Support returning mutable references by using returns #50

Open audunhalland opened 7 months ago

audunhalland commented 7 months ago

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 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.